PowerShell Logo Small


This is the built-in help made by Microsoft for the command 'Set-Alias', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.


Creates or changes an alias (alternate name) for a cmdlet or other command element in the current Windows PowerShell session.


Set-Alias [-Name] <String> [-Value] <String> [-Description [<String>]] [-Force] [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}]
[-InformationVariable [<System.String>]] [-Option {None | ReadOnly | Constant | Private | AllScope | Unspecified}] [-PassThru] [-Scope [<String>]] [-Confirm] [-WhatIf]

Search powershellhelp.space


The Set-Alias cmdlet creates or changes an alias (alternate name) for a cmdlet or for a command element, such as a function, a script, a file, or other executable. You can
also use Set-Alias to reassign a current alias to a new command, or to change any of the properties of an alias, such as its description. Unless you add the alias to the
Windows PowerShell profile, the changes to an alias are lost when you exit the session or close Windows PowerShell.



Online Version: http://go.microsoft.com/fwlink/p/?linkid=294011




-------------------------- EXAMPLE 1 --------------------------

PS C:\>set-alias -name list -value get-childitem

This command creates the alias "list" for the Get-ChildItem cmdlet. After you create the alias, you can use "list" in place of "Get-ChildItem" at the command line and in

-------------------------- EXAMPLE 2 --------------------------

PS C:\>set-alias list get-location

This command associates the alias "list" with the Get-Location cmdlet. If "list" is an alias for another cmdlet, this command changes its association so that it now is the
alias only for Get-Location.

This command uses the same format as the command in the previous example, but it omits the optional parameter names, -Name and -Value. When you omit parameter names, the
values of those parameters must appear in the specified order in the command. In this case, the value of -Name ("list") must be the first parameter and the value of -Value
("get-location") must be the second parameter.

-------------------------- EXAMPLE 3 --------------------------

PS C:\>set-alias scrub remove-item -option readonly -passthru | format-list

This command associates the alias "scrub" with the Remove-Item cmdlet. It uses the "ReadOnly" option to prevent the alias from being deleted or assigned to another cmdlet.

The PassThru parameter directs Windows PowerShell to pass an object that represents the new alias through the pipeline to the Format-List cmdlet. If the PassThru parameter
were omitted, there would be no output from this cmdlet to display (in a list or otherwise).

-------------------------- EXAMPLE 4 --------------------------

PS C:\>Set-Alias np c:\windows\notepad.exe

This command associates the alias, "np", with the executable file for Notepad. After the command completes, to open Notepad from the Windows PowerShell command line, just
type "np".

This example demonstrates that you can create aliases for executable files and elements other than cmdlets.

To make the command more generic, you can use the "Windir" environment variable (${env:windir}) to represent the C\Windows directory. The generic version of the command is
"set-alias np ${env:windir}\notepad.exe".

-------------------------- EXAMPLE 5 --------------------------

PS C:\>function CD32 {set-location c:\windows\system32}
PS C:\>set-alias go cd32

These commands show how to assign an alias to a command with parameters, or even to a pipeline of many commands.

You can create an alias for a cmdlet, but you cannot create an alias for a command that consists of a cmdlet and its parameters. However, if you place the command in a
function or a script, then you can create a useful function or script name and you can create one or more aliases for the function or script.

In this example, the user wants to create an alias for the command "set-location c:\windows\system32", where "set-location" is a cmdlet and "C:\Windows\System32" is the
value of the Path parameter.

To do this, the first command creates a function called "CD32" that contains the Set-Location command.

The second command creates the alias "go" for the CD32 function. Then, to run the Set-Location command, the user can type either "CD32" or "go".