CmdID / PowerShell / Cmdlets / Set
Set-Alias
Creates or changes an alias for a cmdlet or other command in the current PowerShell session. PowerShell reference
From the PowerShell reference
9 parameters
Alias sal
What it does
Creates or changes an alias for a cmdlet or other command in the current PowerShell session. The Set-Alias cmdlet creates or changes an alias for a cmdlet or a command, such as a function, script, file, or other executable. An alias is an alternate name that refers to a cmdlet or command. For example, sal is the alias for the Set-Alias cmdlet. For more information, see about_Aliases. A cmdlet can have multiple aliases, but an alias can only be associated with one cmdlet. You can use Set-Alias to reassign an existing alias to another cmdlet, or change an alias's properties, such as the description. An alias that's created or changed by Set-Alias isn't permanent and is only available during the current PowerShell session. When the PowerShell session is closed, the alias is removed.
Set-Alias [-Name] <string> [-Value] <string> [-Description <string>] [-Option <ScopedItemOptions>] [-PassThru] [-Scope <string>] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]
Create an alias for a cmdlet
PS> Set-Alias -Name list -Value Get-ChildItem
PS> Get-Alias -Name list
CommandType Name
----------- ----
Alias list -> Get-ChildItemIdentifyReassign an existing alias to a different cmdlet
PS> Get-Alias -Name list
CommandType Name
----------- ----
Alias list -> Get-ChildItem
PS> Set-Alias -Name list -Value Get-Location
PS> Get-Alias -Name list
CommandType Name
----------- ----
Alias list -> Get-LocationIdentifyCreate and change a read-only alias
Set-Alias -Name loc -Value Get-Location -Option ReadOnly -PassThru |
Format-List -Property *IdentifyCreate an alias to an executable file
PS> Set-Alias -Name np -Value C:\Windows\notepad.exe
PS> Get-Alias -Name np
CommandType Name
----------- ----
Alias np -> notepad.exeIdentifyCreate an alias for a command with parameters
function CD32 {Set-Location -Path C:\Windows\System32}
Set-Alias -Name Go -Value CD32IdentifyUpdate options for an existing alias
Set-Alias -Name Go -Option ReadOnly, PrivateIdentifyIts page in the reference: Set-Alias.
Parameters
-DescriptionSpecifies a description of the alias. You can type any string. If the description includes spaces, enclose it in single quotation marks.-ForceUse the Force parameter to change or delete an alias that has the Option parameter set to ReadOnly.
The Force parameter can't change or delete an alias with the Option parameter set to Constant.-NameSpecifies the name of a new alias. An alias name can contain alphanumeric characters and hyphens. Alias names can't be numeric, such as 123.-OptionSets the Option property value of the alias. Values such as ReadOnly and Constant protect an alias from unintended changes. To see the Option property of all aliases in the session, type Get-Alias | Format-Table -Property Name, Options -AutoSize.
The acceptable values for this parameter are as follows:
- AllScope - The alias is copied to any new scopes that are created.
- Constant - Can't be changed or deleted.
- None - Sets no options and is the default.
- Private - The alias is available only in the current scope.
- ReadOnly - Can't be changed or deleted unless the Force parameter is used.
- Unspecified
These values are defined as a flag-based enumeration. You can combine multiple values together to set multiple flags using this parameter. The values can be passed to the Option parameter as an array of values or as a comma-separated string of those values. The cmdlet combines the values using a binary-OR operation. Passing values as an array is the simplest option and also allows you to use tab-completion on the values.-PassThruReturns an object that represents the alias. Use a format cmdlet such as Format-List to display the object. By default, Set-Alias doesn't generate any output.-ScopeSpecifies the scope this alias is valid in. The default value is Local. For more information, see about_Scopes.
The acceptable values are as follows:
- Global
- Local
- Private
- Numbered scopes
- Script-ValueSpecifies the name of the cmdlet or command that the alias runs. The Value parameter is the alias's Definition property.-ConfirmPrompts you for confirmation before running the cmdlet.-WhatIfShows what would happen if the cmdlet runs. The cmdlet isn't run.