Posted by: 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:
- 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
- in scripts, functions and anything I publish I try to always use the full cmdlet name
- in scripts I always use the full parameter name
- 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.