PowerShell : Set Alias2019/03/06 |
Set Alias for Cmdlets on PowerShell like follows if you'd like to.
|
|
[1] | Show current Alias. |
PS C:\Users\Administrator> Get-Alias
CommandType Name Version Source
----------- ---- ------- ------
Alias % -> ForEach-Object
Alias ? -> Where-Object
Alias ac -> Add-Content
Alias asnp -> Add-PSSnapin
Alias cat -> Get-Content
Alias cd -> Set-Location
.....
.....
Alias type -> Get-Content
Alias wget -> Invoke-WebRequest
Alias where -> Where-Object
Alias wjb -> Wait-Job
Alias write -> Write-Output
|
[2] | Set new Alias. |
# for example, set [ll] for [Get-ChildItem] PS C:\Users\Administrator> Set-Alias ll Get-ChildItem PS C:\Users\Administrator> Get-Alias ll CommandType Name Version Source ----------- ---- ------- ------ Alias ll -> Get-ChildItem PS C:\Users\Administrator> ll Directory: C:\Users\Administrator Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 3/4/2019 11:58 PM .ssh d-r--- 3/4/2019 11:16 PM Contacts d-r--- 3/4/2019 11:34 PM Desktop d-r--- 3/5/2019 12:05 AM Documents d-r--- 3/4/2019 11:16 PM Downloads d-r--- 3/4/2019 11:16 PM Favorites d-r--- 3/4/2019 11:16 PM Links d-r--- 3/4/2019 11:16 PM Music d-r--- 3/4/2019 11:16 PM Pictures d-r--- 3/4/2019 11:16 PM Saved Games d-r--- 3/4/2019 11:16 PM Searches d-r--- 3/4/2019 11:16 PM Videos |
[3] | Alias you set by yourself are temporary one, when PowerShell end, they are cleared except default Alias, If you always set your own Alias, Set them in []. (Refer to usage of [$profile] here) |
PS C:\Users\Administrator> echo 'Set-Alias ll Get-ChildItem' > $profile
|
[4] | Remove Alias. |
# remove Alias [ll] PS C:\Users\Administrator> Remove-Item alias:ll PS C:\Users\Administrator> Get-Alias ll Get-Alias : This command cannot find a matching alias because an alias with the name 'll' does not exist. At line:1 char:1 + Get-Alias ll + ~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (ll:String) [Get-Alias], ItemNotFoundException + FullyQualifiedErrorId : ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand |
Sponsored Link |