PowerShell : Set Alias2019/02/21 |
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-r--- 2019/02/21 11:36 3D Objects d-r--- 2019/02/21 11:36 Contacts d-r--- 2019/02/21 11:36 Desktop d-r--- 2019/02/21 11:36 Documents d-r--- 2019/02/21 11:36 Downloads d-r--- 2019/02/21 11:36 Favorites d-r--- 2019/02/21 11:36 Links d-r--- 2019/02/21 11:36 Music d-r--- 2019/02/21 11:36 Pictures d-r--- 2019/02/21 11:36 Saved Games d-r--- 2019/02/21 11:36 Searches d-r--- 2019/02/21 11:36 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 [$profile]. (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 |
|