Applies to: Exchange Server 2013

Topic Last Modified: 2012-10-01

You can assign an Exchange Management Shell cmdlet or Cmd.exe command to an administrator-defined and easy-to-remember alias in Microsoft Exchange Server 2013. Such aliases can be handy when you frequently use certain cmdlets and want to reduce the typing that you must do.

When an alias is called from the command line, the rules that apply to the cmdlet that is represented by the alias are enforced exactly as when the cmdlet is called. You must supply any required parameters and their values exactly as if you had called the cmdlet name.

Contents

Built-in aliases

Creating custom aliases

Removing an alias

Importing and exporting aliases

Alias persistence

Alias Limitations

Built-in aliases

Many cmdlets that are used regularly have default, or built-in, aliases assigned to them. These built-in aliases help reduce the typing that you have to do when you administer Exchange 2013 by using the Shell.

For example, the Get-ChildItem cmdlet resembles the MS-DOS Dir command. Because you are familiar with the Dir command, you might want to use the Dir alias when you use the Shell instead of typing Get-ChildItem every time that you want to view the contents of a directory. The output from the Get-ChildItem cmdlet and the Dir alias is the same and can be used interchangeably.

You can view a list of built-in aliases by running the Get-Alias cmdlet in the Shell.

For more information about aliases, run the following command in the Shell.

Copy Code
Get-Help About_Alias

Return to top

Creating custom aliases

In addition to the default, or built-in, aliases, you can define and use custom aliases instead of the names of cmdlets that you frequently use. You can use the Set-Alias cmdlet to associate cmdlets to familiar command names that have the equivalent functionality in Cmd.exe. You can assign multiple aliases to a single command. However, each alias can only be assigned to a single command. For example, you can have three aliases Alias1, Alias2, and Alias3 that are assigned to the New-Mailbox cmdlet. You could then use any of the three aliases to run the New-Mailbox cmdlet. However, each alias that you create can only be assigned to the New-Mailbox cmdlet. You can't, for example, assign Alias1 to both the New-Mailbox cmdlet and the Get-Mailbox cmdlet.

To create a new alias-cmdlet pairing, run the Set-Alias cmdlet and supply the name of the alias, together with the name of the cmdlet that you want to call when the alias is entered.

The following table shows several examples of how to create a new alias.

Examples of custom aliases

Alias description Alias command

Retrieve the contents of a file

Copy Code
Set-Alias Type Get-Content

Retrieve the listing of a directory

Copy Code
Set-Alias Dir Get-ChildItem

Remove a file

Copy Code
Set-Alias Erase Remove-Item

Set pad as an alias for Microsoft WordPad

Copy Code
Set-Alias Pad "${env:programfiles}\Windows NT\Accessories\wordpad.exe"

Display the list of all defined aliases

Copy Code
Set-Alias Aliases Get-Alias

Return to top

Removing an alias

To remove an alias, delete the alias from the alias drive. For example, an administrator creates the Ls alias by using the following command.

Copy Code
Set-Alias Ls Get-ChildItem

Later the administrator decides that the Ls alias is no longer needed and uses the following command to remove the Ls alias.

Copy Code
Remove-Item Alias Ls

Importing and exporting aliases

The Export-Alias cmdlet writes the current alias list to a file in comma-separated values (CSV) format. You can include the name of the file and its path in the command line. If the path doesn't exist, the cmdlet will create the path for you.

The Import-Alias cmdlet reads a text file that has CSV values and brings the list into the Shell as an object. By using the Export-Alias cmdlet and Import-Alias cmdlet, you can export a list of aliases from the Shell on one computer and import them to the Shell on another computer. Because existing predefined aliases exist on both computers, all alias name conflicts will be ignored and not imported.

Alias persistence

Aliases that are created from the command line by using the Set-Alias cmdlet during a Shell session can be used when the session is active. After the session is closed, the alias definition is lost. To make a user-defined alias persistent and available every time that a new Shell session is opened, you must add the alias definition to your Shell profile. You can modify your Shell profile by running the command Notepad $Profile. If the profile directory doesn't exist, you might have to create it first. To find out the path of your profile, run the command $Profile.

Alias limitations

Although aliases can be defined for cmdlets and used instead of cmdlet names, you can't include parameters in the definition of the aliases that you define. You must provide parameters as needed when the alias is called, exactly as you would if you called the cmdlet.

Return to top