Skip to main content
Skip table of contents

new--Logging Jobs with Start-Transcript

Powershell (.ps1) scripts supports much better logging than SQL Server Agent or Windows Task Scheduler (WTS).
The Start-Transcript command captures script and program output at the script level. This level of logging catches error messages that other logging strategies miss. Logging features in application programs for instance don’t begin to capture error messages until sometime after the application program begins running.

In contrast the job logging in SQL Server Agent and WTS is very minimal. 

Example of Logging with PowerShell Start-Transcript

POWERSHELL
#########  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 

Notes

Managing Old Log Files

See new--Deleting Old Files After <n> Days

Related Pages

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.