PowerShell: Listing Alias, Finding Command's Alias
PowerShell commands are usually long. However, PowerShell has aliases. For example, “Get-ChildItem” is the same as “gci” or “dir”.
Working in PowerShell, you'll find yourself needing to know:
- What are existing aliases?
- What is a given cmdlet's aliases?
- What is the cmdlet name for a known alias?
List All Aliases
# show existing aliases Get-Alias # list all aliases ending in r Get-Alias *r
(“Get-Alias” as alias of “gal”)
# find the cmdlet of alias “dir” Get-Alias dir # or, simply use help help dir
List a Cmdlet's Aliases
# list aliases of Get-Childitem Get-Alias -definition get-childitem
Note that the above won't return functions. For example, typing “Get-Alias” will list “help” as a alias for “Get-Help”. However,
Get-Alias -definition Get-Help will return a error. This is because, technically, “help” is the name of a function, not alias.
# list all functions Get-ChildItem function:*
CommandType Name Definition ----------- ---- ---------- Function prompt $(if (test-path variable:/PS... Function TabExpansion ... Function Clear-Host $space = New-Object System.M... Function more param([string]$paths)... Function help ... Function mkdir ... Function Enable-PSRemoting ... Function Disable-PSRemoting ... Function A: Set-Location A: Function B: Set-Location B: Function C: Set-Location C: Function D: Set-Location D: Function E: Set-Location E: Function F: Set-Location F: ... Function cd.. Set-Location .. Function cd\ Set-Location \
PowerShell has over 200 cmdlets and functions. Often, you need to know if there's a command that does what you want. You can search them by Get-Command.
# list all cmdlets whose name has z Get-Command *z* # list all aliases whose name starts with s Get-Command -commandtype alias s*