Code Reference

Aliases Basics

PowerShell · Reference cheat sheet

Aliases Basics

PowerShell · Reference cheat sheet


📋 Overview

Aliases are short names for commands (lsGet-ChildItem, cdSet-Location). They help newcomers from Bash/cmd, but scripts should prefer full cmdlet names for clarity and portability.

🔧 Core concepts

IdeaDetail
Built-in aliasesShip with PowerShell
Custom aliasesSet-Alias / New-Alias for your session
DiscoveryGet-Alias, Alias: drive
Good practiceUse full names in .ps1 files
GalAlias for Get-Alias

Aliases do not support custom parameters the way functions do — use a function for anything non-trivial.

💡 Examples

Common aliases:

ls          # Get-ChildItem
cd $HOME    # Set-Location
pwd         # Get-Location
cat file.txt  # Get-Content (if file exists)
echo "hi"   # Write-Output

Resolve an alias:

Get-Alias ls
Get-Alias | Where-Object Definition -Match "ChildItem"
Get-Command ls

Create a temporary alias:

Set-Alias -Name npp -Value notepad
# npp .\readme.md
Get-Alias npp

Prefer full names in scripts:

# Good in scripts
Get-ChildItem -Path . -File

# Fine interactively
ls -File

⚠️ Pitfalls

  • curl may alias to Invoke-WebRequest in Windows PowerShell — very different from real curl.
  • Aliases you set in a session vanish unless added to your profile.
  • Overloading familiar names can confuse teammates.
  • Aliases are not expanded in all remoting / constrained sessions the same way.

On this page