LTI/ZTI PowerShell: Deployment Script logging

The task sequence step “Run PowerShell Script” has some cool features. One of which is the way it handles information returned from the Write-Host, Write-Warning and Write-Error cmdlets.

MDT collects Information(Write-Host), Warnings(Write-Warning) and Errors(Write-Error) returned from a cmdlet in a script. The information is stored in the deployment logs(BDD.log and also a log with the scriptname).

To test this, I’ve written a simple script, just 3 lines.

Write-Host“This is an Information message.”
Write-Warning“This is a Warning message.”
Write-Error“This is an Error message.”

Running the script returns this at the end of the deployment:

As you can see, the warnings and errors returned from using the Write-Warning and Write-Error cmdlets are displayed at the end of the deployment(although, I’m not sure why it’s tripled the error count).

This yellow screen can generate unnecessary comeback sometimes. In some cases the warning is harmless. So in those situations I use the common parameter –WarningAction “SilentlyContinue” at the end of the script line to supress the messages. This prevents your deployments from looking like they’ve failed when they haven’t really.

Another thing you can try is to add this line to the start of your script.

$WarningPreference = “SilentlyContinue

Right, looking at my output, in the log files MDT has handled all the logs and coded them appropriately.

I’m pleased with this and am sure it will save me having to do a lot of work. Remember, if you call a module that has a function that uses Write-Warning then you will see the yellow screen at the end of your deployments. You may have to edit the function to supress the message as it exists within a different scope.

Advertisements

About Andrew Barnes

A Scripting and Deployment Specialist.
This entry was posted in MDT 2010, MDT 2012, PowerShell, SCCM, Scripting and tagged , , , . Bookmark the permalink.

2 Responses to LTI/ZTI PowerShell: Deployment Script logging

  1. Shouldn’t the Summary screen display in RED if an error has occurred instead of the yellow in your screen cap?

    Like

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s