PowerShell for Windows Admins

May 9 2011   3:37PM GMT

Scripting Games Commentary: X Aliases

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Having stirred up a bit of discussion with my comments about object creation its time to tackle a particular hot button of mine – aliases.

Before I state anything else this is how I use aliases:

  1. at the command line I may use an alias or the full cmdlet name as the mood strikes – though i don’t use % or ? at all
  2. in scripts, functions and anything I publish I try to always use the full cmdlet name
  3. in scripts I always use the full parameter name
  4. the exception to (2) is that I don’t use select-object I use select; I don’t use sort-object I use sort; I don’t use where-object or foreach-object I use where and foreach respectively. Group-Object tends to be group and measure-object gets its full name because I don’t use it very often

 

Not 100% consistent but internally consistent and I tend to stick with this style.

 

Item 2 on the list is the important one. Using the full cmdlet name makes a script more understandable. PowerShell is designed to be easily understood if you use the full cmdlet names and parameter names. The tab completion/intellisense in the Powershell editors makes it easy to use the full names.

Also if you create your own aliases and use them in scripts – your scripts will fail if exported to a machine where the aliases aren’t defined. In the games that is especially true of a judge’s machine. When we have over 1600 scripts to grade if it fails – oops no points.

Keep aliases where they belong – on the command line.

 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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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: