PowerShell CheatSheet – Aliases
An alias is another name assigned to a cmdlet, function, script, executable file, etc. The main purpose is to speed up the call of the command behind and make it easier to remember.
There is a lot of built-in aliases, list that can be obtained by running the following command:
Get-Alias
Yes! Get-Alias has its own alias: gal
The built-in aliases
% foreach > ForEach-Object ? where > Where-Object ac > Add-Content asnp > Add-PSSnapIn cd chdir > Set-Location clc > Clear-Content clear cls > Clear-Host clhy > Clear-History cli > Clear-Item clp > Clear-ItemProperty clv > Clear-Variable compare diff > Compare-Object copy cp cpi > Copy-Item cpp > Copy-ItemProperty cvpa > Convert-Path dbp > Disable-PSBreakpoint del erase rd ri rm rmdir > Remove-Item dir gci ls > Get-ChildItem ebp > Enable-PSBreakpoint echo > Write-Output epal > Export-Alias epcsv > Export-Csv epsn > Export-PSSession etsn > Enter-PSSession exsn > Exit-PSSession fc > Format-Custom fl > Format-List ft > Format-Table fw > Format-Wide gal > Get-Alias gc type > Get-Content gbp > Get-PSBreakpoint gcm > Get-Command gcs > Get-PSCallStack gdr > Get-PSDrive ghy h history > Get-History gi > Get-Item gjb > Get-Job gl > Get-Location gm > Get-Member gmo > Get-Module gp > Get-ItemProperty gps ps > Get-Process grep > Select-String group > Group-Object gsn > Get-PSSession gsnp > Get-PSSnapIn gsv > Get-Service gu > Get-Unique gv > Get-Variable gwmi > Get-WmiObject icm > Invoke-Command iex > Invoke-Expression ihy r > Invoke-History ii > Invoke-Item ipal > Import-Alias ipcsv > Import-Csv ipmo > Import-Module ipsn > Import-PSSession ise > powershell_ise.exe iwmi > Invoke-WMIMethod kill spps > Stop-Process lp > Out-Printer man > help md > mkdir measure > Measure-Object mi move mv > Move-Item mount ndr > New-PSDrive mp > Move-ItemProperty nal > New-Alias ni > New-Item nmo > New-Module nsn > New-PSSession nv > New-Variable ogv > Out-GridView oh > Out-Host popd > Pop-Location pushd > Push-Location pwd > Get-Location rbp > Remove-PSBreakpoint rcjb > Receive-Job rdr > Remove-PSDrive ren rni > Rename-Item rjb > Remove-Job rmo > Remove-Module rnp > Rename-ItemProperty rp > Remove-ItemProperty rsn > Remove-PSSession rsnp > Remove-PSSnapin rv > Remove-Variable rvpa > Resolve-Path rwmi > Remove-WMIObject sajb > Start-Job sal > Set-Alias saps start > Start-Process sasv > Start-Service sbp > Set-PSBreakpoint sc > Set-Content select > Select-Object set sv > Set-Variable sl > Set-Location sleep > Start-Sleep sort > Sort-Object sp > Set-ItemProperty spjb > Stop-Job spsv > Stop-Service swmi > Set-WMIInstance tee > Tee-Object wjb > Wait-Job write > Write-Output
In the above list, there’s another interresting alias: sal, for Set-Alias
Set-Alias gives us the ability to create new aliases of our own (for good, instead of New-Alias which also creates an alias, but only for the current session). Let’s say that we want to create an alias to quickly launch a script, MonitorWP.ps1 for example. Here’s the command to do so:
Set-Alias MWP Drive:\Path\To\The\Script\MonitorWP.ps1
So now, instead of calling the script by
Drive:\Path\To\The\Script\MonitorWP.ps1
we only have to type
MWP