Home ยป PowerShell ยป New-Alias in PowerShell to create Alias

New-Alias in PowerShell to create Alias

New-Alias cmdlet in PowerShell creates a new alias for the specified cmdlet for the current session in PowerShell. Alias names created using New-Alias are not saved after you close the PowerShell session.

In this article, we will discuss how to create new alias in PowerShell using the New-Alias cmdlet and read-only alias for a cmdlet.

New-Alias in PowerShell

Syntax

New-Alias
   [-Name] <String>
   [-Value] <String>
   [-Description <String>]
   [-Option <ScopedItemOptions>]
   [-PassThru]
   [-Scope <String>]
   [-Force]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

Parameters

-Name: Specify the name of the new alias. It accepts only alphanumeric characters for an alias name.

-Description: Specify the description of the alias.

-Scope: Specify the scope for the new alias. It can take Global, Local, or Script value. Local is the default value.

-Value: Specify the cmdlet name that is being used for aliased.

Create New Alias for Cmdlet

Using the New-Alias cmdlet in PowerShell, you can create a new alias for a cmdlet.

New-Alias -Name "teeo" Tee-Object  

In the above PowerShell script, the New-Alias cmdlet uses the Name parameter to specify the new alias name for the cmdlet Tee-Object.

New-Alias creates the new alias for the cmdlet and is available for the current session in PowerShell only. Once you close the PowerShell or exit the session, it will not save the alias name.

The output of the above command to create a PowerShell command alias is:

New-Alias - PowerShell command Alias
New-Alias โ€“ PowerShell command Alias

Cool Tip: How to remove PowerShell alias!

How to Create Read-Only alias for PowerShell Command

Use the New-Alias cmdlet to create a PowerShell command alias. It creates a description for the alias and makes it read-only using the Option parameter.

New-Alias -Name "G" -Value Get-Command -Description "Quick GC alias" -Option ReadOnly
Get-Alias -Name "G" | Format-List *  

In the above PowerShell script to create a PowerShell command alias, the New-Alias cmdlet uses the Name parameter to specify an alias named โ€œGโ€ and creates a Description for the alias using the Description parameter.

Get-Alias cmdlet in PowerShell uses the Name parameter to retrieve all aliases for the name starting with the letter โ€œGโ€.

PowerShell new alias
PowerShell new alias

Cool Tip: How to set an alias in PowerShell!

Conclusion

I hope the above article on how to create a PowerShell command alias using the New-Alias cmdlet is helpful to you.

Alias name created using the New-Alias cmdlet is not saved after you close the PowerShell or exit the session.

Cool Tip: How to import alias in PowerShell!

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.