PowerShell for Windows Admins

Aug 31 2019   11:43AM GMT

Pet peeves

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Tags:
Powershell

Back in July I mentioned the using ? instead of Where-Object was a pet peeve. I’ve been asked a few times since for other pet peeves. The order of peevishness changes over time but these three will probably be always near the top.

In no particular order.

Peeve – the use of aliases in scripts. Aliases are fine for interactive use but when coding scripts or modules you should ALWAYS use the full cmdlet name and parameter names. If you use VScode or ISEsteroids you’ll find warning messages about the use of aliases. The problem with using aliases is that it makes the code harder to maintain especially for new comers. if you want to write impenetrable code that no one can read then switch to Perl. PowerShell has verb-noun cmdlet naming conventions and good (usually) parameter names for a reason. It makes the code easier to read and therefore understand and maintain. I guarantee that you’d rather inherit some code that uses full names rather than all aliases – been there, done that and its painful.

Peeve – the use of posh as an abbreviation for PowerShell. Its not needed and doesn’t add anything to the conversation. Just don’t.

Peeve – the use of multiple calls to Add-Member to create an object. You had to do this back in PowerShell v1. You should use New-Object or create a class to define your object. Its more efficient and easier to maintain. Don’t keep using outdated techniques just because there are still examples on the Internet.

I’ll publish more peeves sometime in the future.

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: