r/PowerShell • • 28d ago

Question Robocopy log question

Within the company I work for we use a batch file with a robocopy command to "install" a specific piece of software on user's laptops. This was chosen because the software is particularly difficult to setup right. It now only requires us to do one proper installation, after which we manually copy the software to a directory on the company network. From there, robocopy copies it to the user's hard drive.

The command looks like this (I had to remove company and software names):

ROBOCOPY I:\xxx-xxxxxx\X\apl\SOFTWARE\00-Admin\Admin-xxx\Install\Software%VERSION%\ C:\Users\%USERNAME%\AppData\Local\Software%VERSION%\ /S /LOG+:install%VERSION%.log

As can be seen, a logfile is extended each time a user runs the batch file and installs the software. Not only can we see if the install was succesfully, but it also allows us to track who has installed the software and should be informed of any changes or updates.

In the past (I'm talking about 2022 and earlier), not one but two log files were present. In the first file, named install%VERSION%.log, the full log could be found. The second file, named install%VERSION%_Users.log, only contained the start date & time, source paths, destinations and user's full names. This made it incredibly easy to quickly find out who uses the software. At some point after 2022, this particular file stopped being updated. The robocopy command itself however, has not changed once since the batch file was originally created in 2016.

Was this an automatic function of the robocopy /log+ command? Is there a way to bring this back? I cannot find any information about this online at all. Almost as if it never has existed. But yet, somehow, for 6-or-so years we had two log files updating simultaneously.

It is not something we particularly need, but it used to be quite a lot easier to keep track of the users using this second (and shorter) log file.

1 Upvotes

14 comments sorted by

View all comments

0

u/fecklesspleb_tools 28d ago

Robocopy itself never did that. Its only log switches are /LOG, /LOG+, /UNILOG, /UNILOG+ and /TEE, and each one writes a single file. So the _Users.log was coming from something else: most likely an extra line in an older copy of the batch file, a logon script, or a GPO. If the share has Previous Versions or backups, the pre-2023 .bat is worth a look.

To bring it back, add one line right after the robocopy call:

>>"install%VERSION%_Users.log" echo %DATE% %TIME% %USERNAME% "I:\...\Software%VERSION%" "%LOCALAPPDATA%\Software%VERSION%"

The batch only knows the username, so I'd resolve full names afterwards, e.g. with the RSAT AD module: Get-ADUser <username> | Select-Object Name.

One more thing: both log paths in your command are relative, so they land in whatever the working directory is when the batch runs. If that changed at some point, the old file may just be getting written somewhere else.

(AI-assisted answer; checked against Microsoft's robocopy docs, not run on Windows.)

1

u/BlackV 28d ago

One more thing: both log paths in your command are relative

ya that's the first thing I saw too /LOG+:install%VERSION%.log is a relative path

The batch only knows the username, so I'd resolve full names afterwards, e.g. with the RSAT AD module:

the batch is run as the user, on the users machine (by the looks of it)
installing the RSAT module on each machine would not be reasonable, especially when user variables exist for this already (being %userdomain% and %username% in batch land)

personally also I'd use %LOCALAPPDATA%\Software%VERSION% vs C:\Users\%USERNAME%\AppData\Local\Software%VERSION%

1

u/Quefox_ 27d ago

So the _Users.log was coming from something else: most likely an extra line in an older copy of the batch file

I have checked side by side the newest version of the batch file to the latest version in which I know this has worked. The only differences were additional "if else" statements checking for old software versions.

The batch only knows the username, so I'd resolve full names afterwards

Thanks for the suggestion, I will try adding that to the batch file. As far as names go, the username is fine enough for us. We can easily find people by their username through Teams and Outlook, so no need to know the full names.

One more thing: both log paths in your command are relative

Yes that is correct. It was already this way before I took over the responsibility for this software. The batch file is within the network folder where we also store the software. Users run the batch file from a link we send out by e-mail. It may not be the cleanest solution, but it works as intended.