PowerShell Aliases
PowerShell aliases are alternative descriptors (usually abbreviations) for PowerShell commandlets.
What are PowerShell Aliases?
Just like nicknames for names, aliases are shorter versions of command invoke names. It works with functions, scripts, files, or even executable files too.
PowerShell already includes these cmdlets designed for working with aliases:
- Get-Alias (Gets all active aliases in the session)
- New-Alias (Creates a new alias)
- Set-Alias (Changes an alias)
- Export-Alias (Exports aliases to a file)
- Import-Alias (Imports an alias file)
To understand the acronyms of which the aliases consist, you might want to learn more about acronyms, which we covered in our article about the PowerShell scripting language.
How do you create aliases in PowerShell?
In order to create a new alias, just use the New-Alias command. As an example, if „GoTo“ as an alias should take over the function of „Set-Location“, type:
New-Alias -Name GoTo -Value Set-Location
This does not create a permanent PowerShell Alias, as it will be gone after the current session has been closed. But aliases can be stored to be executed anytime PowerShell is executed.
Tutorial: PowerShell Aliasing
PowerShell Aliasing is one of the main ways to speed up work with any command line and avoid errors. Visit our Blog to learn more about PowerShell Aliases!
How do you display all aliases in PowerShell
In order to get all currently active PowerShell command aliases, type:
Get-Alias
If a single alias should be displayed, one can use the Get-Alias with the alias together or the Name Parameter with the Get-Alias cmdlet (e.g. Set-Alias „sal“):
Get-Alias sal
Get-Alias -Name -sal
Maybe the whole alias is not known, (or to save time instead of typing the whole Alias) try the following to show a list of all aliases starting with the letters
Get-Alias -Name -s*
PowerShell Alias Provider
For Power users, especially interesting might be the already integrated PowerShell Alias Provider, which lists the aliases in a register just as they were on a file system drive. To access the Alias: drive, type:
Set-Location Alias:
For a more detailed introduction into the alias provider, visit the official Microsoft PowerShell site.