TOPIC
about_aliases
SHORT DESCRIPTION
Describes how to use alternate names for cmdlets and commands in Windows
PowerShell.
LONG DESCRIPTION
An Alias is an alternate name or nickname for a cmdlet or for a command
element, such as a Function, script, file, or executable file. You
can use the Alias instead of the command name in any Windows PowerShell
commands.
To create an Alias, use the New-Alias cmdlet. For example, the following
command creates the “gas” Alias for the Get-AuthenticodeSignature cmdlet:
New-Alias -name gas -value Get-AuthenticodeSignature
After you create the Alias for the cmdlet name, you can use the Alias
instead of the cmdlet name. For example, to get the Authenticode signature
for the SqlScript.ps1 file, type:
Get-AuthenticodeSignature sqlscript.ps1
Or, type:
gas sqlscript.ps1
If you create “word” as the Alias for Microsoft Office Word, you can type
“word” instead of the following:
“c:\program files\microsoft office\office11\winword.exe”
BUILT-IN AliasES
Windows PowerShell includes a set of built-in Aliases, including “cd” and
“chdir” for the Set-Location cmdlet, and “ls” and “dir” for the
Get-ChildItem cmdlet.
To get all the Aliases on the computer, including the built-in Aliases,
type:
ALIAS CMDLETS
Windows PowerShell includes the following cmdlets, which are designed for
working with Aliases:
– Get-Alias. Gets all the 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:
Get-Help <cmdlet-name> -detailed
For example, type:
Get-Help Export-Alias -detailed
CREATING AN Alias
To create a new Alias, use the New-Alias cmdlet. For example, to create the
“gh” Alias for Get-Help, type:
New-Alias -name gh -value Get-Help
You can use the Alias in commands, just as you would use the full cmdlet
name, and you can use the Alias with parameters.
For example, to get detailed Help for the Get-WmiObject cmdlet, type:
Get-Help Get-WmiObject -detailed
Or, type:
gh Get-WmiObject -detailed
SAVING AliasES
The Aliases that you create are saved only in the current session. To use
the Aliases in a different session, add the Alias to your Windows
PowerShell profile. Or, use the Export-Alias cmdlet to save the Aliases to
a file.
For more information, type:
Get-Help about_profile
GETTING AliasES
To get all the Aliases in the current session, including the built-in
Aliases, the Aliases in your Windows PowerShell profiles, and the Aliases
that you have created in the current session, type:
To get particular Aliases, use the Name parameter of the Get-Alias cmdlet.
For example, to get Aliases that begin with “p”, type:
Get-Alias -name p*
To get the Aliases for a particular item, use the Definition parameter.
For example, to get the Aliases for the Get-ChildItem cmdlet type:
Get-Alias -definition Get-ChildItem
ALTERNATE NAMES FOR COMMANDS WITH PARAMETERS
You can assign an Alias to a cmdlet, script, Function, or executable file.
However, you cannot assign an Alias to a command and its parameters.
For example, you can assign an Alias to the Get-EventLog cmdlet, but you
cannot assign an Alias to the “Get-Eventlog -logname system” command.
However, you can create a Function that includes the command. To create a
Function, type the word “function” followed by a name for the Function.
Type the command, and enclose it in braces ({}).
For example, the following command creates the syslog Function. This
Function represents the “Get-Eventlog -logname system” command:
Function syslog {Get-Eventlog -logname system}
You can now type “syslog” instead of the command. And, you can create
Aliases for the syslog Function.
For more information about Functions, type:
ALIAS OBJECTS
Windows PowerShell Aliases are represented by objects that are instances
of the System.Management.Automation.AliasInfo class. For more information
about this type of object, see “AliasInfo Class” in the Microsoft
Developer Network (MSDN) library at
http://go.microsoft.com/fwlink/?LinkId=143644.
To view the properties and methods of the Alias objects, get the
Aliases. Then, pipe them to the Get-Member cmdlet. For example:
To view the values of the properties of a specific Alias, such as the
“dir” Alias, get the Alias. Then, pipe it to the Format-List cmdlet. For
example, the following command gets the “dir” Alias. Next, the command
pipes the Alias to the Format-List cmdlet. Then, the command uses the
Property parameter of Format-List with a wildcard character (*) to display
all the properties of the “dir” Alias. The following command performs
these tasks:
Get-Alias -name dir | Format-List -property *
WINDOWS POWERSHELL Alias PROVIDER
Windows PowerShell includes the Alias provider. The Alias provider lets you
view the Aliases in Windows PowerShell as though they were on a file system
drive.
The Alias provider exposes the Alias: drive. To go into the Alias: drive,
type:
To view the contents of the drive, type:
To view the contents of the drive from another Windows PowerShell drive,
begin the path with the drive name. Include the colon (:). For example:
Get-ChildItem -path Alias:
To get information about a particular Alias, type the drive name and
the Alias name. Or, type a name pattern. For example, to get all the
Aliases that begin with “p”, type:
Get-ChildItem -path Alias:p*
For more information about the Windows PowerShell Alias provider,
type:
SEE ALSO
New-Alias
Get-Alias
Set-Alias
Export-Alias
Import-Alias
Get-PSProvider
Get-PSDrive
about_functions
about_profiles
about_providers