PowerShell : Set Alias2024/12/02 |
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--- 12/1/2024 4:19 PM Contacts d-r--- 12/1/2024 4:19 PM Desktop d-r--- 12/1/2024 4:49 PM Documents d-r--- 12/1/2024 4:19 PM Downloads d-r--- 12/1/2024 4:19 PM Favorites d-r--- 12/1/2024 4:19 PM Links d-r--- 12/1/2024 4:19 PM Music d-r--- 12/1/2024 4:19 PM Pictures d-r--- 12/1/2024 4:19 PM Saved Games d-r--- 12/1/2024 4:19 PM Searches d-r--- 12/1/2024 4:19 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 [$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 |
|