We create PowerShell Alias by utilizing the Set-Alias cmdlet. After setting an Alias, memory will save overall details of the command with their Alias. As a result, you can call the command at any time with their specified Alias or print out the defined Aliases using the Get-Alias cmdlet.
This post will teach us how to create Alias in PowerShell.
How to create Alias in PowerShell?
The Set-Alias cmdlet is used in PowerShell to create an alias. In this cmdlet, specify the full name of the command for which you want to set an Alias. After setting Alias, utilize the Get-Alias command to print out the Alias.
Syntax
The syntax of Set-Alias in PowerShell is given as:
Here, you have to add the Alias as <string> with the -Name option and the required command name as <string> with -Value option.
Example 1
Let’s check an example to set an alias of cmdlet Get-Location by using the above-defined syntax:
Here, we will set the Alias Location for cmdlet Get-Location:
Now, you will be able to use the Get-Location command using the Location Alias. Moreover, if you want to verify the name of the defined Alias, execute the Get-Alias cmdlet:
Example 2
In PowerShell, there are built-in Aliases for some commands that are used, such as ac for the Add-Content cmdlet and many more. To get the list of built-in Aliases, utilize the Get-Alias cmdlet:
In this example, we will modify the Alias write to wrOtpt for the Write-Output cmdlet:
To do so, we will use the Set-Alias cmdlet to overwrite the existing Alias:
Using Get-Alias cmdlet, verify the result of the previously performed operation:
In the below snippet, you can see that the Alias write is now overwritten with wrOtpt Alias:
We have covered important details about PowerShell Alias. I hope it will be helpful for you.
Conclusion
Alias is a short title or an alternative name for the cmdlet. You can use the Set-Alias cmdlet for creating or changing any existing Alias. For this purpose, utilize the Set-Alias [-Name] <string> [-Value] <string> syntax, where you have to add the Alias as <string> with the -Name option and the required command name as <string> with -Value option. Then, verify the name of the defined Alias with the Get-Alias command. This blog demonstrated the method to create PowerShell Alias.