Windows 2022
Sponsored Link

PowerShell : Set Alias2022/12/23

 
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           CFS -> ConvertFrom-String                          3.1.0.0    Microsoft.PowerShell.Utility

.....
.....

Alias           trcm -> Trace-Command
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/23/2022  12:12 AM                3D Objects
d-r---        12/23/2022  12:12 AM                Contacts
d-r---        12/23/2022  12:12 AM                Desktop
d-r---        12/23/2022  12:19 AM                Documents
d-r---        12/23/2022  12:12 AM                Downloads
d-r---        12/23/2022  12:12 AM                Favorites
d-r---        12/23/2022  12:12 AM                Links
d-r---        12/23/2022  12:12 AM                Music
d-r---        12/23/2022  12:12 AM                Pictures
d-r---        12/23/2022  12:12 AM                Saved Games
d-r---        12/23/2022  12:12 AM                Searches
d-r---        12/23/2022  12:12 AM                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
Matched Content