PowerShell Script to send backup log output to console and to a log file with Start-Transcript


PowerShell Script to send backup log output to console and to a log...
Author
Message
Ceje
Ceje
New Member
New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)
Group: Forum Members
Posts: 14, Visits: 108
I have a client that needs to run Reflect manually at his discretion. I modified the PowerShell script provided by MR for my own needs and it works quite well. It is launched from a shortcut with "Run as Administrator". The Console displays everything perfectly, but the output file created with Start-Transcript displays everything except the output from the MR backup. I have read this thread https://forum.macrium.com/21233/How-to-catch-PowerShell-backup-script-output-to-a-file and wondered if a solution has been found that might resolve my problem.
Thanks for the help

Here is some of the code that might show in greater detail what I am trying to accomplish:
#******************************************************************************
# Get the Day Of The Week (Sunday-Saturday)
#   Duplicate everything on the console into the output file
#  
#******************************************************************************
$strDayOfWeek = (Get-Date).DayOfWeek;
$strOuputFileName = "C:\Users\Owner\OneDrive\Documents\Reflect\^Backuplog" + $strDayOfWeek + ".log";
Start-Transcript -Path $strOuputFileName;
.........
function Backup()
{
Write-Host ' * BACKUP STARTED... ' -NoNewLine;
#$strType = GetBackupTypeParameter;  This is not needed since I get that information from the user via Read-Host
$strArgs = "-v `"$strXmlFilePath`"";    # I'm using -v as a test to see if the MR output is written to the log file
$iResult = (Start-Process -FilePath $strReflectPath -ArgumentList $strArgs -PassThru -Wait).ExitCode;

jphughan
jphughan
Macrium Evangelist
Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)
Group: Forum Members
Posts: 14K, Visits: 85K
In the thread you linked above, the very last post, written by yours truly, references a Reflect update where Macrium added support for a change you can make to the way ReflectBin is called in your script to achieve exactly what you want. Here is the link to the KB article: https://knowledgebase.macrium.com/plugins/servlet/mobile?contentId=14123795#content/view/14123795

Edited 6 July 2021 4:56 PM by jphughan
Ceje
Ceje
New Member
New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)
Group: Forum Members
Posts: 14, Visits: 108
That works great to output all the MR backup to a file, but I need it to be displayed on the console also so my client can be impressed and comforted by seeing the process progress in real time. Additionally, I need a log file to refer back to, in case an error occurred. The log file generated by Start-Transcript seemed like a simple way to get one and  still allow the client to see the MR output also.
jphughan
jphughan
Macrium Evangelist
Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)
Group: Forum Members
Posts: 14K, Visits: 85K
I can’t test this at this exact moment, but my recollection is that adding that parameter to send log output to a file does NOT prevent the output from being displayed in the console. Is that not consistent with your experience?
jphughan
jphughan
Macrium Evangelist
Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)
Group: Forum Members
Posts: 14K, Visits: 85K
Never mind, for some reason I thought RedirectStandardOutput could be used without NoConsole. Can your client not achieve interactive visibility by simply looking at the ReflectMonitor application, which can be accessed from its system tray icon or (by default) by pressing Ctrl+Alt+M (for Macrium)?
Edited 6 July 2021 5:08 PM by jphughan
Ceje
Ceje
New Member
New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)New Member (20 reputation)
Group: Forum Members
Posts: 14, Visits: 108
With your suggestions here is the workaround I'm going to have to live with. It's ugly but I guess it will have to do.
I have a PowerShell log created by Start-Transcript named BackupPS.log
I also have a MR log created by ReflectBin.exe named BackupMR.log
To view the progress of the MR backup my customer will use the SysTray MR ICON to Show/Hide the backup progress.
To review what happened in the job I will have to access 2 files.

I was hoping that something simpler and more elegant might have been implemented since 2018.
It would have been so easy (from my perspective) to use Start-Transcript and everything seen on the console would be logged to a single file.

I'm disappointed because of this, but MR is still a fantastic piece of software.
Thanks for your great help.

Edited 8 July 2021 6:53 PM by Ceje
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Login

Explore
Messages
Mentions
Search