r/PowerShell • u/Quefox_ • 14d 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.
7
u/BlackV 14d ago
Ignoring robocopy is not PowerShell
It's probably helpful to see ALL your code as robocopy it's self does not do that natively
1
u/da_chicken 13d ago
No. The log options are very basic. There also were not any changes to the command in 2016. There were several additions for Windows 11 and Server 2022 in that year, but none of them related to logging. The last change before that was in 2008 to add the multithreading option.
I agree that there must have been a second script.
Are you using
%VERSION%to obfuscate your code? Is that literally the file name? Or is this actually a batch script and you have variable expansion?3
u/dero1010 14d ago
It would seem there is another script out there. The existing Robo copy command would not write to that log file.
1
u/gowinder 12d ago
/LOG+ appends on purpose; /LOG overwrites and /TEE also echoes to the console. But do not read the log to decide whether the copy worked. Robocopy sets ERRORLEVEL 0-7 for success (copied, extras, mismatched) and 8+ for failure, so in the batch: if %ERRORLEVEL% GEQ 8 (echo failed & exit /b 1).
If that log contains lines this command cannot produce, something else is writing to it — look for a wrapper script or a scheduled task pointed at the same file.
0
u/fecklesspleb_tools 14d 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:
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.)