Home » PowerShell » Get-Alias in PowerShell

Get-Alias in PowerShell

Get-Alias cmdlet gets the alias list for the current session in PowerShell. PowerShell alias list includes built-in aliases, aliases that you have added, or aliases that have been imported or set by you.

Get-Alias returns the command name based on the alias name. If you want to return the command alias list, use the Definition parameter.

In this article, we will learn about Get-Alias in PowerShell, and how to use Get-Alias to get a PowerShell alias list or find aliases in the current session.

Get-Alias PowerShell

Get-Alias returns alias names for PowerShell cmdlets. Get-Alias takes alias name as input and returns the cmdlet name.

By default, Get-Alias retrieves all aliases defined for the current session in PowerShell.

Alias name for Get-Alias cmdlet in PowerShell is gal

Syntax

Get-Alias
   [[-Name] <String[]>]
   [-Exclude <String[]>]
   [-Scope <String>]
   [<CommonParameters>]

Get-Alias
   [-Exclude <String[]>]
   [-Scope <String>]
   [-Definition <String[]>]
   [<CommonParameters>]

Parameters

-Name: Specify the aliases to retrieve. The Name is an optional parameter. You can use wildcards.

-Definition: Gets the alias for the specified item.

-Scope: Specify the scope for which the Get-Alias will be valid. The scope can accept Global, Local, and Script. By default, Scope is Local.

Get Alias in PowerShell for the current session

Use the Get-Alias cmdlet in PowerShell to get all aliases in the current session.

Get-Alias

The output of the above PowerShell Get-Alias cmdlets retrieves all aliases in the current session.

PS C:\> Get-Alias                                                                                                       
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           % -> ForEach-Object
Alias           ? -> Where-Object
Alias           ac -> Add-Content
Alias           asnp -> Add-PSSnapin
Alias           cat -> Get-Content
Alias           cd -> Set-Location
Alias           CFS -> ConvertFrom-String                          3.1.0.0    Microsoft.PowerShell.Utility
Alias           chdir -> Set-Location
Alias           clc -> Clear-Content
Alias           clear -> Clear-Host
Alias           clhy -> Clear-History
Alias           cli -> Clear-Item
Get-Alias - PowerShell Alias List
Get-Alias – PowerShell Alias List

Cool Tip: How to use PowerShell Set-Alias cmdlet!

Get all aliases by Name

Use the Name parameter of the Get-Alias cmdlet to get all aliases that start with a character or name. You can use wildcards.

Get-Alias -Name gc*  

In the above PowerShell script, the Get-Alias cmdlet uses the Name parameter to specify the alias name with wildcards to get all aliases name that begins with gc.

The output of the above PowerShell script is:

PS C:\> Get-Alias -Name gc*                                                                                             
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           gc -> Get-Content
Alias           gcb -> Get-Clipboard                               3.1.0.0    Microsoft.PowerShell.Management
Alias           gci -> Get-ChildItem
Alias           gcm -> Get-Command
Alias           gcs -> Get-PSCallStack


PS C:\>   

Cool Tip: How to create a new alias for the PowerShell command!

Get Cmdlet Alias in PowerShell

You can get aliases for the specified cmdlet using the Get-Alias with the Definition parameter.

 Get-Alias -Definition Get-Command

In the above PowerShell script, the Get-Alias command uses the Definition parameter to specify the cmdlet name and retrieves the alias list in PowerShell.

The output of the above command is:

PS C:\> Get-Alias -Definition Get-Command                                                                               
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           gcm -> Get-Command


PS C:\>    

Cool Tip: How to remove PowerShell alias!

Get Aliases by Property

You can use the Get-Alias cmdlet to get all aliases by property.

Get-Alias | Where-Object {$_.Options -Match "ReadOnly"}

In the above PowerShell script, the Get-Alias command finds all aliases in which the Options property is ReadOnly.

Cool Tip: How to get details of files in a folder using PowerShell!

Conclusion

I hope the above article on the Get-Alias cmdlet to get aliases list in PowerShell is helpful to you.

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