PROVIDER NAME
Alias
DRIVES
Alias:
SYNOPSIS
Provides access to the Windows PowerShell Aliases and the values that they represent.
DESCRIPTION
The Windows PowerShell Alias provider lets you get, add, change, clear, and delete Aliases in Windows PowerShell.
An Alias is an alternate name for a cmdlet, Function, or executable file. Windows PowerShell includes a set of built-in Aliases. And, you can add your own Aliases to the current session and to your Windows PowerShell profile.
The Alias provider is a flat namespace that contains only the Alias objects. The Aliases have no child items.
Each Alias is an instance of the System.Management.Automation.AliasInfo class.
The Alias provider exposes its data store in the Alias: drive. To work with Aliases, you can change your location to the Alias: drive by using the following command:
Or, you can work from any other Windows PowerShell drive. To reference an Alias from another location, use the Alias: drive name in the path.
Windows PowerShell includes a set of cmdlets that are designed to view and to change Aliases:
Export-Alias
Get-Alias
Import-Alias
New-Alias
Set-Alias
When you use these cmdlets, you do not need to specify the Alias: drive in the name.
The Alias provider supports all the cmdlets that have the Item noun except for the Invoke-Item cmdlet. And, it supports the Get-Content and Set-Content cmdlets. The Alias provider does not support the cmdlets that have the ItemProperty noun. And, the Alias provider does not support the Filter parameter in any cmdlet.
All changes to the Aliases affect the current session only. To save the changes, add the changes to the Windows PowerShell profile. Or, use the Export-Alias and Import-Alias cmdlets.
CAPABILITIES
TASKS
TASK: Getting to the Alias: Drive
————————– EXAMPLE 1 ————————–
This command changes the current location to the Alias: drive. You can use this command from any drive in Windows PowerShell. To return to a file system drive, type the drive name. For example, type “Set-Location c:”.
TASK: Getting Aliases
————————– EXAMPLE 1 ————————–
This command gets a list of all the Aliases in the current session. You can use this command in any Windows PowerShell drive.
————————– EXAMPLE 2 ————————–
This command gets the “ls” Alias. Because it includes the path, you can use it in any Windows PowerShell drive.
If you are in the Alias: drive, you can omit the drive name from the path.
————————– EXAMPLE 3 ————————–
This command gets a list of the Aliases that are associated with the Get-ChildItem cmdlet. It uses the Definition property, which stores the cmdlet name.
Get-Item -path Alias:* | Where-Object {$_.Definition -eq “Get-ChildItem“}
When the Aliased item is an executable file, the Definition contains the fully qualified path of the file.
————————– EXAMPLE 4 ————————–
This command gets the list of all the Aliases when the current location is the Alias: drive. It uses a wildcard character (*) to indicate all the contents of the current location.
Get-Item -path *
In the Alias: drive, a dot (.), which represents the current location, and a wildcard character (*), which represents all items in the current location, have the same effect. For example, “Get-Item -path .” or “Get-Item *” produce the same result.
TASK: Creating a New Alias
————————– EXAMPLE 1 ————————–
This command creates the “serv” Alias for the Get-Service cmdlet. Because the current location is in the Alias: drive, the value of the Path parameter is a dot (.). The dot represents the current location.
This command also uses the Options dynamic parameter to set the AllScope and Constant options on the Alias. The Options parameter is available in the New-Item cmdlet only when you are in the Alias: drive.
New-Item -path . -name serv -value Get-Service -Options “AllScope,Constant”
If you are in the Alias: drive, you can omit the drive name from the path.
————————– EXAMPLE 2 ————————–
You can create an Alias for any item that invokes a command. This command creates the “np” Alias for Notepad.exe.
New-Item -path Alias:np -value c:\windows\notepad.exe
————————– EXAMPLE 3 ————————–
You can create an Alias for any Function. You can use this feature to create an Alias that includes both a cmdlet and its parameters.
The first command creates the CD32 Function, which changes the current directory to the System32 directory. The second command creates the “go” Alias for the CD32 Function. The semi-colon (;) is the command separator.
When the command is complete, you can use either “CD32” or “go” to invoke the Function.
Function CD32 {Set-Location -path c:\windows\system32} Set-Item -path Alias:go -value CD32
TASK: Displaying the Properties and Methods of Aliases
————————– EXAMPLE 1 ————————–
This command uses the Get-Item cmdlet to get all Aliases. The pipeline operator (|) sends the results to the Get-Member cmdlet, which displays the methods and properties of the object.
Get-Item -path Alias:* | Get-Member
When you pipe a collection of objects to Get-Member, such as the collection of Aliases in the Alias: drive, Get-Member evaluates each object in the collection separately. Then, Get-Member returns information about each object type that it finds. If all the objects are of the same type, it returns information about the single object type. In this case, all the Aliases are AliasInfo objects.
To get information about the collection of AliasInfo objects, use the InputObject parameter of Get-Member. For example, use the following command:
Get-Member -InputObject (Get-Item Alias:*)
When you use InputObject, Get-Member evaluates the collection, not the objects in the collection.
————————– EXAMPLE 2 ————————–
This command lists the values of the properties of the “dir” Alias. It uses the Get-Item cmdlet to get an object that represents the “dir” Alias. The pipeline operator (|) sends the results to the Format-List command. The Format-List command uses the Property parameter with a wildcard character (*) to format and display the values of all the “dir” Alias properties.
Get-Item Alias:dir | Format-List -property *
TASK: Changing the Properties of an Alias
————————– EXAMPLE 1 ————————–
You can use the Set-Item cmdlet with the Options dynamic parameter to change the value of the Options property of an Alias.
This command sets the AllScope and ReadOnly options for the “dir” Alias. The command uses the Options dynamic parameter of the Set-Item cmdlet. The Options parameter is available in Set-Item only when you use it with the Alias or Function provider.
Set-Item -path Alias:dir -options “AllScope,ReadOnly”
————————– EXAMPLE 2 ————————–
This command uses the Set-Item cmdlet to change the “gp” Alias so that it represents the Get-Process cmdlet instead of the Get-ItemProperty cmdlet. The Force parameter is required because the value of the Options property of the “gp” Alias is set to ReadOnly. Because the command is submitted from within the Alias: drive, the drive is not specified in the path.
Set-Item -path gp -value Get-Process -force
The change affects the four properties that define the association between the Alias and the command. To view the effect of the change, type the following command:
Get-Item -path gp | Format-List -property *
————————– EXAMPLE 3 ————————–
This command uses the Rename-Item cmdlet to change the “popd” Alias to “pop”.
Rename-Item -path Alias:popd -newname pop
TASK: Copying an Alias
————————– EXAMPLE 1 ————————–
This command copies the pushd Alias so that a new push Alias is created for the Push-Location cmdlet.
Copy-Item -path Alias:pushd -destination Alias:push
When the new Alias is created, its Description property has a null value. And, its Option property has a value of None.
If the command is issued from within the Alias: drive, you can omit the drive name from the value of the Path parameter.
TASK: Deleting an Alias
————————– EXAMPLE 1 ————————–
This command deletes the serv Alias from the current session. You can use this command in any Windows PowerShell drive.
Remove-Item -path Alias:serv
If you are in the Alias: drive, you can omit the drive name from the path.
————————– EXAMPLE 2 ————————–
This command deletes Aliases that begin with “s”. It does not delete read-only Aliases.
Clear-Item -path Alias:s*
————————– EXAMPLE 3 ————————–
This command deletes all Aliases from the current session, except those with a value of Constant for their Options property. Without the Force parameter, the command does not delete Aliases whose Options property has a value of ReadOnly.
Remove-Item Alias:* -force
DYNAMIC PARAMETERS
-Options <System.Management.Automation.ScopedItemOptions>
Determines the value of the Options property of an Alias.
None
No options. This value is the default.
Constant
The Alias cannot be deleted and its properties cannot be changed. Constant is available only when you create an Alias. You cannot change the option of an existing Alias to Constant.
Private
The Alias is visible only in the current scope, not in the child scopes.
ReadOnly
The properties of the Alias cannot be changed except by using the Force parameter. You can use Remove-Item to delete the Alias.
AllScope
The Alias is copied to any new scopes that are created.
Cmdlets Supported: New-Item, Set-Item
NOTES
RELATED LINKS
about_aliases
about_providers