Posts RSS Comments RSS 253 Posts and 411 Comments till now

Using Aliases in Scripts or in your Examples.

Richard has a post on his blog about this The Over Use of Aliases?

I dont like duplicating other peoples post, but I think this one is worth it.

If you are an experienced Powershell person and you provide help or scripts to people. PLEASE do not use aliases. It makes it very hard for people. I am guilty myself. I mean gc % ? gm are SO tempting, but it really doesn’t help the person learn (it may even hinder.) IMO, using aliases can confuse newcomers… remember to them when you type gc… they think it is gc.exe not get-content. Peoples first impression is key… lets not make it a confusing one 🙂

Basically, I think aliases are best use for interactive use, but should be avoided in scripts or sample code.

p.s. COMMENT… COMMENT… COMMENT… Comments in code help a ton for people learning.

Jeffrey brought up a good point that I over looked. Numerous Powershell IDE’s like PrimalScript and Powershell Analzyer automatically expand built in aliases. I find this very useful. I will be writing another post about IDE’s and why I think they are VERY important.

2 Responses to “Using Aliases in Scripts or in your Examples.”

  1. on 27 Jun 2007 at 9:40 amKevin

    In my opinion, all “production” code should be fully un-aliased. Certainly anything distributed should be stripped of all aliases.

    Beyond that if your code relies on a 3rd party snapin. Use the Snapin/Cmdlet convention to 100% disambiguate which Cmdlet should be called. This will ensure that you don’t end up with a broken script because of naming conflicts.

  2. on 28 Jun 2007 at 12:19 amJeffrey Snover

    I hear you.

    PrimalScript has this cool feature that goes through your script and expands all your aliases (or contracts cmdlets -> aliases). Don Jones demonstarted this in one of my talks and it brought the house down!

    Jeffrey Snover [MSFT]
    Windows Management Partner Architect
    Visit the Windows PowerShell Team blog at:
    Visit the Windows PowerShell ScriptCenter at:

Trackback this post | Feed on Comments to this post

Leave a Reply

You must be logged in to post a comment.