Powershell - Alias


Advertisements

PowerShell alias is another name for the cmdlet or for any command element.

Creating Alias

Use New-Alias cmdlet to create a alias. In the below example, we've created an alias help for Get-Help cmdlet.

New-Alias -Name help -Value Get-Help  

Now invoke the alias.

help Get-WmiObject -Detailed  

You will see the following output.

NAME
   Get-WmiObject
    
SYNOPSIS
   Gets instances of Windows Management Instrumentation (WMI) classes or information about the available classes.    
    
SYNTAX
   Get-WmiObject [
...

Getting Alias

Use get-alias cmdlet to get all the alias present in current session of powershell.

Get-Alias

You will see the following output.

CommandType     Name                     Definition
-----------     ----                     ----------  
Alias           %                        ForEach-Object
Alias           ?                        Where-Object
Alias           ac                       Add-Content
Alias           asnp                     Add-PSSnapIn 
...
Advertisements