PowerShell aliases are shortcuts that help you type commands more quickly. Instead of typing out full cmdlet names, you can use shorter alternatives. Here are some of the aliases you’ve probably come across before:
Alias Cmdlet Description
ls Get-ChildItem List items in a directory (like ls in Linux)
cd Set-Location Change the current directory
pwd Get-Location Print the current directory path
clear Clear-Host Clear the terminal screen
cat Get-Content Display the contents of a file
In PowerShell, the ls
command is an alias for Get-ChildItem
, so it uses the parameters of Get-ChildItem
, not those of the ls
command in Linux.
PowerShell does not support Linux-style parameters like -l
or -1
for this alias.
Creating Your Own Aliases
You can create aliases for PowerShell cmdlets and even things like control panel settings and executables.
# Creates an alias 'ct' to quickly open Control Panel
New-Alias -Name ct -Value control.exe
# Creates an alias 'app' to open the Programs and Features window
New-Alias -Name app -Value appwiz.cpl
# Creates an alias 'touch' to quickly create new items
New-Alias -Name touch -Value New-Item
Getting aliases
To list aliases for a specific cmdlet use the definition parameter of Get-Alias
.
Get-Alias -Definition Get-ChildItem
CommandType Name
----------- ----
Alias dir -> Get-ChildItem
Alias gci -> Get-ChildItem
Alias ls -> Get-ChildItem
To get aliases by name, you would use the name parameter and combine that with exclude:
Get-Alias -Name gp*, sp* -Exclude *ps
CommandType Name
----------- ----
Alias gp -> Get-ItemProperty
Alias gpv -> Get-ItemPropertyValue
Alias sp -> Set-ItemProperty
Alias spjb -> Stop-Job
Alias spsv -> Stop-Service
Use Case
One example that I use in my environment is having a quick way to sign a PowerShell script. You would normally use the Set-AuthenticodeSignature
command, but you need to provide a Code signing certificate and time stamp server.
To make things easier you could wrap the cmdlet and it’s parameters in a function and create an alias for the function.
$cert = Get-ChildItem Cert:\CurrentUser\My -CodeSigningCert |
Select-Object -First 1
function Set-ScriptSignature {
param (
[string]$FilePath
)
$signatureParams = @{
FilePath = $FilePath
Certificate = $cert
TimestampServer = "http://timestamp.digicert.com"
}
Set-AuthenticodeSignature @signatureParams
}
Set-Alias -Name SignMyScript -Value Set-ScriptSignature
With this method you will only need to provide the file path.
SignMyScript -FilePath c:\temp\script.ps1
Making Aliases Permanent
To make your aliases permanent, add them to your PowerShell profile:
First, check if you have a profile:
Test-Path $PROFILE
If it doesn’t exist, create it:
New-Item -Path $PROFILE -Type File -Force
Add your aliases to the profile using your preferred text editor.
# Open your profile in VS Code
code $PROFILE
Or, if you prefer another editor:
Notepad $PROFILE
Note: When I type code
in the terminal, Visual Studio Code opens. This might seem like an alias at first glance, but it’s not! The code
command is added to your system's PATH during the installation of VS Code (or from the editor settings later).
You could also add new aliases in your profile using just PowerShell:
$newAliases = @'
#region Aliases
New-Alias -Name touch -Value New-Item
New-Alias -Name cp -Value control.exe
#endregion Aliases
'@
Add-Content -Path $PROFILE -Value $newAliases
Other useful aliases
The following tip is a quick way to open folders from the command line.
ii c:\temp\
You could even create an alias for a folder that you open often.
function Open-Projects {
Invoke-Item -Path "C:\github"
}
Set-Alias -Name openProjects -Value Open-Projects
etsn is an alias for Enter-PSSession which is used to connect interactively to another computer.
etsn SVR001
Best Practices
Use aliases for interactive work only
Use full cmdlet names in scripts for better readability
Avoid overwriting built-in aliases
Document custom aliases in your profile
Remember that while aliases are great for quick terminal work, it’s recommended to use full cmdlet names in scripts and shared code for better maintainability.
Got your favorite PowerShell alias? Share it in the comments, and let’s build a list of time-saving tricks!