Home » PowerShell » Remove Alias in PowerShell

Remove Alias in PowerShell

Remove-Alias cmdlet in PowerShell is used to remove an alias name for PowerShell cmdlet in the current session. If you want to delete an alias name from all sessions, add the Remove-Alias cmdlet in your PowerShell profile.

To delete an alias with the Option property set to Read-Only, use the Force parameter.

Note: Remove-Alias cmdlet is supported in PowerShell 6. Check your PowerShell version by $PSVersionTable. Use Remove-Item for PowerShell 5.x version.

In this article, we will discuss how to use Remove-Alias in PowerShell to remove an alias from the current session.

PowerShell Remove-Alias

PowerShell remove-alias cmdlet deletes an alias from the current session.

Syntax

Remove-Alias
      [-Name] <String[]>
      [-Scope <String>]
      [-Force]
      [<CommonParameters>]

Parameters

-Name: Specify the alias name to remove

-Scope: Specify the scope. It deletes alias in the specified scope only. The default scope is Local. Acceptable values for the Scope parameter are Global, Local, or Script.

-Force: It indicates that Remove-Alias removes an alias including aliases with the Option property set to ReadOnly

Remove Alias in PowerShell

Use the Remove-Alias cmdlet in PowerShell to remove the alias for the PowerShell command from the current session.

Remove-Alias -Name C

In the above PowerShell script, Remove-Alias uses the Name parameter to specify the name of the alias and delete the alias in the PowerShell session.

Let’s understand with creating new alias for cmdlet in PowerShell and removing the alias.

PS C:\> Set-Alias -Name C -Value Get-Content

PS C:\> Get-Alias -Name C

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           C -> Get-Content

PS C:\> Remove-Alias -Name C

PS C:\> Get-Alias -Name C
Get-Alias: This command cannot find a matching alias because an alias with the name 'C' does not exist.
PS C:\>   

In the above PowerShell script, the Set-Alias cmdlet uses the Name parameter C to specify the alias name for the Get-Content cmdlet.

The Get-Alias cmdlet uses the Name parameter to specify the alias name C and retrieve the alias list in the PowerShell session.

The Remove-Alias cmdlet uses the Name parameter to specify the name of the alias C to delete the alias for the PowerShell cmdlet from the current session. It removes the alias name for the command.

If we try to execute the Get-Alias command with the name of the alias C, it gives the message as an alias with the name ‘C’ does not exist.

Cool Tip: How to import alias in PowerShell!

Conclusion

I hope the above article on how to use Remove-Alias in PowerShell to delete Powershell alias is helpful to you.

Use the Remove-Alias Force parameter to remove an alias having the Option property set to ReadOnly.

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