Use the other Write- cmdlets

One of the unsung features of PowerShell are the many ways to provide output.  For completely automated script via Scheduled Task or Orchestrator, I go straight to the Event Log now. 

But for the majority of scripts you’ll run on the command line, there is a lot more than Write-Output.  By the way, Don Jones says God kills a puppy each time you use Write-Host, so don’t do that.

Write-Debug

Excellent for trace level information and you can enable/disable with –Debug and $DebugPreference.

Write-Verbose         

· Step by step information like “Now running trash compactor…”, switched with –Verbose and $VerbosePreference.

Write-Warning         

Show of hands, who actually knew this was there?  Now you do.  Switched with –WarningAction and $WarningPreference.

Write-Error

Looks just like a regular paragraph long red error message, switched with –ErrorAction and $ErrorPreference.

I’m moving all inline comments to Write actions and making decisions about the right level of notice along the way.  I definitely like the ability to control output when running scripts now.

Advertisements
This entry was posted in PowerShell. Bookmark the permalink.

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