Code Reference

Useful Commands

PowerShell · Reference cheat sheet

Useful Commands

PowerShell · Reference cheat sheet


📋 Overview

A compact toolkit of high-frequency PowerShell commands for files, processes, networking, and discovery. Prefer cmdlets in scripts; aliases are fine interactively. PowerShell 7+ (pwsh) is recommended for cross-platform work.

🔧 Core concepts

AreaGo-to cmdlets
FilesGet-ChildItem, Copy-Item, Move-Item, Remove-Item, Get-Content, Set-Content
SearchSelect-String, Where-Object
ProcessGet-Process, Stop-Process, Start-Process
NetTest-Connection, Test-NetConnection, Invoke-WebRequest
SystemGet-Service, Get-ComputerInfo (Win)
HelpGet-Help, Get-Command, Get-Member
PathJoin-Path, Resolve-Path, Split-Path, Test-Path

Operators: -replace, -split, -join, redirection >, >>, 2>, *>.

💡 Examples

Files and search:

Get-ChildItem -Recurse -Filter *.md |
  Select-String -Pattern 'TODO' |
  Select-Object Path, LineNumber, Line

Get-Content .\app.log -Tail 50 -Wait

Processes and ports (Win):

Get-Process | Sort-Object CPU -Descending | Select-Object -First 10
Test-NetConnection example.com -Port 443
Get-NetTCPConnection -State Listen | Select-Object LocalPort, OwningProcess

Quick JSON / clipboard (Win):

Invoke-RestMethod https://api.github.com/zen
Set-Clipboard (Get-Location).Path

Discovery:

Get-Command *Item*
Get-Help about_Operators

⚠️ Pitfalls

  • rm, ls, cat are aliases—behavior differs from GNU tools.
  • Remove-Item -Recurse without -Force may prompt; in PS 5.1 -Recurse quirks exist—test first.
  • curl alias confusion on Windows PowerShell 5.1.
  • Prefer -LiteralPath when names contain [ wildcards.
  • Admin-required cmdlets fail silently or access-denied—check elevation.
  • Don’t use Write-Host when you need pipeline data.

On this page