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. But 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 Move-Mailbox cmdlet. You could then use any of the three aliases to run the Move-Mailbox cmdlet. However, each alias that you create can only be assigned to the Move-Mailbox cmdlet. You can't, for example, assign Alias1 to both the Move-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.
Table 2 shows several examples of how to create a new alias.
Table 2 Examples of custom aliases
|
Alias description
|
Alias command
|
|---|
|
Retrieve the contents of a file.
|
Set-Alias Type Get-Content
|
|
Retrieve the listing of a directory.
|
Set-Alias Dir Get-ChildItem
|
|
Remove a file.
|
Set-Alias Erase Remove-Item
|
|
Set pad as an alias for Microsoft WordPad.
|
Set-Alias Pad "${env:programfiles}\Windows NT\Accessories\wordpad.exe"
|
|
Display the list of all defined aliases.
|
Set-Alias Aliases Get-Alias
|