Xah Lee, 2009-07
PowerShell commands are usually long. For example: Get-ChildItem. However, PowerShell has aliases. For example, “dir” is the same as “Get-ChildItem”. You can create your own aliases.
Working in PowerShell, you'll find yourself needing to know:
# show existing aliases get-alias # list all aliases ending in r get-alias *r
# find the cmdlet of alias “dir” get-alias dir # or, simply use help help dir
# find the aliases of Get-Childitem get-alias -definition get-childitem
Note that the above won't return functions. For example, typing “get-alias” will show “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 dir function:*
Sample output:
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 has alias gcm gcm *z* # list all aliases whose name starts with s gcm -commandtype alias s*
# creating a new alias xx for get-childitem new-alias xx get-childitem
Alias works only in the current session. To create perm alias, put them in your PowerShell init file. e.g.: 〔C:\Users\xah\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1〕.
To see your config, type:
# show all aliases Get-Variable profile | Format-Listblog comments powered by Disqus