Powershell

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

An alias is a short name for a cmdlet, script, or function. PowerShell’s “Get-Alias” cmdlet is used to get the aliases for the current session and return the alias names for the cmdlets. It gets aliases including built-in, imported, and also the ones added by the user. By default, PowerShell takes an alias name and returns cmdlet. However, it has a “-Definition” parameter that takes the cmdlet and returns its alias.

This guide will elaborate on the “Get-Alias” cmdlet in PowerShell.

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

The cmdlet “Get-Alias” is utilized to retrieve the alias names for the cmdlets in PowerShell. Let’s have a look at the given examples to learn the usage of the stated cmdlet.

Example 1: Use the “Get-Alias” Cmdlet to Retrieve All the Aliases

Execute the given command to retrieve the current session’s aliases:

Get-Alias

Example 2: Use the Cmdlet “Get-Alias” to Get Aliases by Name

First, use the “Get-Alias” cmdlet. Then, write the “-Name” parameter and specify the provided names along with the wild character “*” to display the selected aliases:

Get-Alias -Name cl*, cp*

Example 3: Use the “Get-Alias” Cmdlet to Get an Alias for a Specific Cmdlet

To get a cmdlet’s alias, first, use the “Get-Alias” cmdlet. Then, specify the “-Definition” parameter and provide it with the below-mentioned cmdlet:

Get-Alias -Definition Clear-Host

Example 4: Use the “Get-Alias” Cmdlet to Get an Alias by Name and Filter it Using a Predefined Name

Initially, use the “Get-Alias” cmdlet. Then, write the “-Definition” parameter and specify the stated value along with the wild character “*” at the start. Lastly, use the “-Scope” parameter and assign the “Local” value to the scope:

Get-Alias -Definition "*-Host" -Scope Local

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

Conclusion

PowerShell’s “Get-Alias” cmdlet gets the alias names of the cmdlets in the current session only. It gets aliases of the cmdlets, functions, or scripts. This post illustrated the “Get-Alias” cmdlet with the help of various 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.