PowerTip: Find the Length of PowerShell Aliases

PowerTip: Find the Length of PowerShell Aliases

  • Comments 4
  • Likes

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

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • 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!?)

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

  • Hi

    another option:

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

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