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.