In the past I’ve made various posts giving examples of how PowerShell can be perfect for the the lazy sysadmin through not having to type as much. This can be done through using aliases instead of the full cmdlet and truncating parameters (only available with PS v2 remember, you old-school v1 users will have to upgrade). For example, why type all of…
Get-ChildItem u:\scripts -Include *.ps1 –Recurse
…when you could simply type…
gci U:\Scripts -i *.ps1 –r
For simply running stuff from within PS the shorter version is ideal. Problem arises when you start to copy-and-paste your one-liners into a script, that then gets put into production, that then might have to be revised / debugged / fixed by someone else in the future? Am guilty as charged as have done this myself on numerous occasions, in an attempt to affirm my alpha-geek status. Trouble is it all falls apart when one of your team asks you what one of your scripts is doing and you struggle to come up with a reasonable explanation.
So what lessons am I going to try and learn from this?
- If I’m going to insist on trying to make my typing as little as possible I’ll back up my code with enough comments (but then kind of defeats the object of reduced typing!)
- Use full cmdlet and parameter names in scripts (and comments!) as if I don’t its only going to come back and bite me anyway.
No comments:
Post a Comment