PowerShell Logo Small

Set-Alias



This is the built-in help made by Microsoft for the command 'Set-Alias', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' 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.

SYNOPSIS

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

SYNTAX


Set-Alias [-Name] <string> [-Value] <string> [-Description <string>] [-Force] [-Option {None | ReadOnly | Constant | Private | AllScope}] [-PassT
hru] [-Scope <string>] [-Confirm] [-WhatIf] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


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 clo
se Windows PowerShell.



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkID=113390
Get-Alias
New-Alias
Export-Alias
Import-Alias

REMARKS

<

Examples


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

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



Description
-----------
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 scripts.








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

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



Description
-----------
This command associates the alias "list" with the Get-Location cmdlet. If "list" is an alias for another cmdlet, this command changes its associa
tion 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 o
mit 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 --------------------------

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



Description
-----------
This command associates the alias "scrub" with the Remove-Item cmdlet. It uses the "ReadOnly" option to prevent the alias from being deleted or a
ssigned 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 --------------------------

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



Description
-----------
This command associates the alias, "np", with the executable file for Notepad. After the command completes, to open Notepad from the Windows Powe
rShell 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 --------------------------

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

C:\PS>set-alias go cd32



Description
-----------
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:\W
indows\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".