When running Macrium Reflect from a PowerShell script it may be desirable to pipe the backup log to a text file for further processing. If you try to action this using -RedirectStandardOutput in the script this will result in a 0 byte file.
Why isn't the output populating the file?
Macrium Reflect is a Windows GUI application and, unlike the Console subsystem, GUI applications do not automatically map stdout and stderr streams to a parent console Window. Because of this, Macrium Reflect calls AttachConsole and maps stdout and stderr to the parent console Window buffer - CONOUT$. Unfortunately, this can lead to the output being 'lost' if there is no console Window,
Macrium Reflect v7.1.2899 has added a new parameter in the command line, -noconsole , that enables redirection of stdout and stderr. The following solution involves modifying a generated script using Macrium Reflect. You can use the same principles for your own script if different.
At the top of the source file change the file name to run from 'Reflect.exe' to 'ReflectBin.exe'.Note: If the script was generated with Macrium Reflect version 7.1.2899 or later then this step isn't necessary
In function 'Backup()', add -noconsole to the Reflect parameter list '$strArgs' and -RedirectStandardOutput with your log file name to the 'Start-Process' line as shown below:
The script will now pipe log output to the log file name provided with the -RedirectStandardOutput switch.