As we discussed in the previous lesson, PowerShell PowerShell aliases allows to create the commands which we are familiar in other shells like Windows Command Prompt or Unix shells from PowerShell cmdlets.
Some examples of built-in aliases are
• "gal" is the alias for Get-Alias cmdlet.
• "cd" is the alias for Set-Location cmdlet.
• "dir" is the alias for Get-ChildItem cmdlet.
• "ls" is another alias for Get-ChildItem cmdlet, for those who are accustomed with Unix shells.
To view all built-In PowerShell Aliases use the command Get-Alias.
To set an alias, use the command Set-Alias. Example, if you want to create a new alias "listdirectory" to list the contents of a directory, you can use the following command.
PS C:\> Set-Alias listdirectory Get-ChildItem
The screenshot of the Set-Alias command inside PowerShell window is shown below.
To list the contents of a directory use the new alias "listdirectory", in PowerShell. The output of the "listdirectory" alias is shown below.
To remove an alias, use the cmdlet Remove-Item as shown below.
PS C:\> Remove-Item alias:\listdirectory