Finding Aliases for a Command

by Mar 25, 2009

PowerShell defines a lot of shortcuts (aliases) for most commands. You may want to determine whether there is a shortcut if you find yourself using some commands repeatedly. Use the Get-CmdletAlias function below to find them:

function Get-CmdletAlias( $cmdlet  ) {
if ( (Get-Command $cmdlet).CommandType -eq 'Alias') {
$cmdlet = (Get-Command $cmdlet).Definition

Get-Alias | Where-Object { $_.Definition -eq $cmdlet } |
ForEach-Object { $_.Name }

"Aliases for dir:"
Get-CmdletAlias dir
"Aliases for Foreach-Object:"
Get-CmdletAlias ForEach-Object