Task Scheduler PowerShell Script Log File

This is a continuation to my earlier posts PowerShell Error Log File and Export and Email … Using Powershell. This is also a test of the WP.com Gist code snippet support. The following script sample is intended to provide ideas for collecting exception output from a PowerShell script in a log file and then optionally emailing the error log to yourself (conditional on the success or failure status of your script). This type of script error log wrapper would typically be scheduled to run through Windows Task Scheduler to automate something repetitive.

Important cmdlets used include Start-Transcript and Send-MailMessage. This also features the use of Automatic Variable $LASTEXITCODE.

About notesbytom

Keeping technology notes on WordPress.com to free up my mind to solve new problems rather than figuring out the same ones repeatedly :-).
This entry was posted in System Administration and tagged , , , . Bookmark the permalink.

1 Response to Task Scheduler PowerShell Script Log File

  1. Jonathan Devenish says:

    Great Script, thanks heaps!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s