Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Example of Logging with PowerShell Start-Transcript

Writes the log to a file with date and time. For example: RunLog_2023_08_23@12-30.txt.
The file path is based on the location of the script. For example: <path-to-the-script-file>\Run_Logs\ RunLog_2023_08_23@12-30.txt.

Code Block
languagepowershell
#########  Start Logging  ######################################### 
$DateTimeStr = Get-Date -UFormat   %Y-%m-%d@%H-%M     # date-time string for log file name 
[string]$RunLogsPath = "$($PSScriptRoot)\Run_Logs"     # path for log file created below 
[string]$Transcript_FileRef = "$($RunLogsPath)\RunLog_$DateTimeStr.txt" 
Start-Transcript -Path $Transcript_FileRef -Append -Verbose 

...