PowerTip: Find the Length of PowerShell Aliases

Summary: See how to determine the distribution of Windows PowerShell cmdlet aliases by length.

Hey, Scripting Guy! Question How many Windows PowerShell aliases are 1-letter or 2-letters or 3-letters in length? In fact, how do you determine what the entire distribution of cmdlet alias lengths is?

Hey, Scripting Guy! Answer Use the Get-Alias cmdlet to retrieve all of the aliases. Then pipe the aliases to the Foreach-Object cmdlet and convert them to strings and retrieve the length property.
             After you have done that, pipe the results to the Group cmdlet and sort by the name property (which will be the actual length of the alias.

Get-Alias | % {$_.tostring().length} | group -NoElement | sort name -Descending

Comments (4)

  1. Bigteddy says:

    I really like these daily tips.  They are great, keep it up!

  2. aaron says:

    I use Powershell very often, and I think that it improves many aspects of even the Bourne Again Shell! However, I would like to be removed from the mailing list for this blog. I'm using a Windows Live (@live.com) account, and can't figure out how to subscribe to (let alone unsubscribe from or list) RSS feeds. Any help you could provide would be much appreciated. (bonus points for using powershell/curl to do it!?)

  3. Walid Toumi says:


    another option:

    PS II> gal | group {$_.name.length}  -n

  4. Walid Toumi says:

    PS II> gal | group {$_.name.length}  | sort name -Desc

Skip to main content