Wednesday, January 09, 2013

Dispatching Puppies

I mentioned in a talk I gave yesterday how bunnies did not fare so well when people use Write-Host.  That was guidance I  gleaned from Don Jones’ (PowerShell MVP) Proverbs:

Every time someone writes a PowerShell script that outputs text, rather than objects, God kills a puppy.

This came out in one of Don's PowerShell classes at a conference, as a way of driving home the fact that PowerShell is an object-based shell, not a text-parsing system. Working with the shell, rather than against it, makes for a more efficient administrator and a better experience for all.

In general when you’re using Write-Host, you should usually be using Write-Verbose or Write-Warning.

Also, if you find yourself formatting output, chances are you’re doing it wrong.  PowerShell is all about objects, so output objects.  Formatting should be the very last thing that happens (if at all).

No comments: