PowerTip: Find the Length of PowerShell Aliases

Doctor Scripto

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


Discussion is closed.

Feedback usabilla icon