Powershell

How to Use the Remove-Alias (Microsoft.PowerShell.Utility) Cmdlet in PowerShell?

In PowerShell, the cmdlet “Remove-Alias” remove an alias name specified to a command in the current session. However, to remove the alias from all the sessions, simply, add the “Remove-Alias” cmdlet to the PowerShell profile. The “Remove-Alias” cmdlet was first introduced in PowerShell 6.0 and it does not have any standard alias. Moreover, to remove the read-only alias, simply specify the “-Force” parameter along with the “Remove-Alias” cmdlet.

This tutorial will elaborate on the usage of PowerShell’s “Remove-Alias” cmdlet.

How to Use/Utilize the Remove-Alias (Microsoft.PowerShell.Utility) Cmdlet in PowerShell?

To remove an alias and its information in PowerShell, first, use the “Remove-Alias” cmdlet. Then, write the “-Name” parameter and provide it with an alias name. To understand furthermore usage of the stated cmdlet, head over to the below given practical examples section.

Example 1: Use the Cmdlet “Remove-Alias” to Remove an Alias

Before deleting or removing an alias, let’s verify if an alias exists or not. For that purpose, simply run the alias name in PowerShell:

Getp

As it can be observed that the alias name exists. Now, let’s delete it.

To remove an alias, first, use the “Remove-Alias” cmdlet. Then, add the “-Name” parameter and assign it the alias name:

Remove-Alias -Name "Getp"

To check whether the alias has been removed or not, run the provided example:

Getp

As it can be observed that the specified alias has been deleted successfully:

Example 2: Use the “Remove-Alias” Cmdlet to Remove ReadOnly Alias

To remove the “ReadOnly” alias, use the “-Force” parameter alongside the “Remove-Alias” cmdlet:

Remove-Alias -Name "Gets" -Force

Example 3: Use the “Remove-Alias” Cmdlet to Remove all Non-ReadOnly Aliases

To delete aliases except “ReadOnly”, execute the provided command:

Get-Alias | Where-Object { $_.Options -NE "ReadOnly" } | Remove-Alias -Force

According to the above-specified command:

  • First, use the “Get-Alias” cmdlet and pipe it to the “Where-Object” cmdlet.
  • Next, create a condition to select an alias except “ReadOnly” and pipe it to the “Remove-Alias” cmdlet.
  • Lastly, use the “-Force” parameter to delete the “ReadOnly” aliases:

That’s it! You have learned the usage of the PowerShell “Remove-Alias” cmdlet.

Conclusion

PowerShell’s “Remove-Alias” cmdlet removes the aliases for the cmdlets in the current session. It can also remove the aliases for all the sessions by specifying them in the PowerShell profile. Aliases with the read-only option can also be removed utilizing the parameter “-Force”. This guide explained the usage of the “Remove-Alias” cmdlet with the help of various practical examples.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.