Using alternate names for cmdlets and commands in Windows PowerShell
An alias is an alternate name or nickname for a cmdlet or a command element, such as a function, script, file, or executable file. You can use the alias in place of the command name.
For example, if you establish the alias "gas" for Get-AuthenticodeSignature, you can type:
If you establish "word" as the alias for Microsoft Word, you can type:
Windows PowerShell includes a set of predefined aliases, including "cd" and "chdir" for Set-Location, and "ls" and "dir" for Get-Childitem.
To find all of the aliases on the system, including the predefined aliases, type:
Windows PowerShell includes several cmdlets designed for working with aliases.
· Get-Alias: Gets all aliases in the current session.
· New-Alias: Creates a new alias.
· Set-Alias: Creates or changes an alias.
· Export-Alias: Exports one or more aliases to a file.
· Import-Alias: Imports an alias file into Windows PowerShell.
For detailed information about the cmdlets, type:
CREATING AN ALIAS
To create a new alias, use the New-Alias cmdlet. For example, to create the "gh" alias for Get-Help, type,
You can use the alias in commands, just as you would use the full cmdlet name, including parameters.
For example, to get detailed help for the Get-WmiObject cmdlet, you can type:
- or -
The aliases that you create are saved only to the current session. To use the aliases in a different session, you must add the alias to your Windows PowerShell profile or use Export-Alias to save the aliases to a file.
To find all of the aliases in the current console, including the aliases that Windows PowerShell defines, the aliases in your Windows PowerShell profile, and the aliases that you have created in the current session, type:
To get particular aliases, use the Name parameter of Get-Alias. For example, to get aliass that begin with "p", type
To find the aliases for a particular cmdlet, type:
ALTERNATE NAMES FOR COMMANDS WITH PARAMETERS
You can assign an alias to a cmdlet, script, function, or executable file, but you cannot assign an alias to a command and its parameters. For example, you can assign an alias to "Get-Eventlog", but you cannot assign an alias to "Get-Eventlog -logname security".
However, you can create a function that includes the command. For example, the following command creates a function called "seclog" that represents the "get-eventlog -logname security" command.
You can now type "seclog" instead of the command, and you can create aliases to the "seclog" function.
For information about functions, type:
Windows PowerShell aliases are represented by objects that are instances of the System.Management.Automation.AliasInfo class. For information about this type of object, see the "AliasInfo Class" topic in MSDN.
To see the properties and methods of the alias objects, get the aliases and pipe them to the Get-Member cmdlet. For example,
To see the values of the properties for a particular alias, such as the "dir" alias, get the alias and pipe it to the Format-List cmdlet. For example, the following command gets the "dir" alias, pipes it to the Format-List cmdlet, and uses the Property parameter of Format-List with a value of all (*) to display all properties of the "dir" alias.
WINDOWS POWERSHELL ALIAS PROVIDER
Windows PowerShell includes an Alias provider that lets you view the aliases in Windows PowerShell as though they were in a file system drive.
The Alias provider exposes a drive called "Alias:". To go into the Alias: drive, type:
To see the contents of the drive, type:
To see the contents of the drive from any other Windows PowerShell drive, begin the path with the drive name, including the colon(:). For example,
To get information about a particular alias, type the drive name and the alias name, or a name pattern. For example, to get all of the aliases that begin with "p," type:
For more information about the Windows PowerShell Alias provider, type:
For a list the alias-related cmdlets, type:
For information about functions, type: