Aliases

An alias in PowerShell is an alternate name for a command. A command may have more than one alias.

The list of aliases may be viewed by using Get-Alias, as shown in the following example:

PS> Get-Alias

CommandType Name
----------- ----
Alias % -> ForEach-Object
Alias ? -> Where-Object
Alias ac -> Add-Content
Alias asnp -> Add-PSSnapin
Alias cat -> Get-Content
Alias cd -> Set-Location

Get-Alias may be used to find the command behind an alias:

Get-Alias dir 

It can also be used to find the aliases for a command name:

Get-Alias -Definition Get-ChildItem 

Examples of aliases that are frequently used in examples on the internet include the following:

  • % for ForEach-Object
  • ? for Where-Object
  • cd for Set-Location
  • gc or cat for Get-Content
  • ls or dir for Get-ChildItem
  • man for help (and then Get-Help)

An alias does not change how a command is used. There is no practical difference between the following two commands:

cd $env:TEMP 
Set-Location $env:TEMP 

New aliases are created with the New-Alias command; for example, we might choose to create an alias named grep for Select-String:

New-Alias grep -Value Select-String 

Each alias exists until the PowerShell session is closed.

More information is available about aliases in the help file, which may be viewed using the following command: Get-Help about_Aliases.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.131.238