Finding Aliases for a Command

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

Posted Mar 25 2009, 08:00 AM by ps1
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.