Cheatsheet: PowerShell

Last updated 2026-09-28

Cmdlet Basics & Help

Get help for a cmdlet (with examples)

Get-Help Get-Process -Examples

List commands matching a name or pattern

Get-Command *process*

List every property/method a cmdlet's output has

Get-Process | Get-Member

List available cmdlet verbs

Get-Verb

Use a short built-in alias for a cmdlet

ls, gci, cat, gc, cd, rm, cp, ps, kill

Filesystem & Items

List items in the current directory

Get-ChildItem

List items recursively, filtered by name

Get-ChildItem -Recurse -Filter *.log

Change directory

Set-Location C:\Path

Print working directory

Get-Location

Create a new file or directory

New-Item -Path .\file.txt -ItemType File

Copy / move / remove an item

Copy-Item, Move-Item, Remove-Item

Read a file's contents

Get-Content .\file.txt

Test whether a path exists

Test-Path C:\Path

Pipeline: Filter, Select, Sort

Filter objects by a property condition

Get-Process | Where-Object CPU -gt 100

Select specific properties

Get-Process | Select-Object Name, CPU

Select the first / last N objects

Get-Process | Select-Object -First 5

Sort by a property, descending

Get-Process | Sort-Object CPU -Descending

Run a script block per pipeline item

1..5 | ForEach-Object { $_ * 2 }

Group objects by a property

Get-Process | Group-Object Company

Measure count/sum/average of a property

Get-Process | Measure-Object CPU -Sum -Average

Processes & Services

List running processes

Get-Process

Stop a process by name or ID

Stop-Process -Name notepad

Start a new process

Start-Process notepad.exe

List services and their status

Get-Service

Start / stop / restart a service

Start-Service, Stop-Service, Restart-Service

Variables & Scripting

Assign a variable

$name = "value"

String interpolation (double quotes only)

"Hello, $name!"

If / elseif / else

if ($x -gt 0) { "positive" } elseif ($x -eq 0) { "zero" } else { "negative" }

Comparison operators (not <, >, ==)

-eq, -ne, -gt, -lt, -ge, -le, -like, -match

Foreach loop over a collection

foreach ($item in $collection) { $item }

Define a function with a parameter

function Greet($name) { "Hello, $name" }

Convert pipeline objects to JSON

Get-Process | Select-Object Name, Id -First 3 | ConvertTo-Json

Remoting & Sessions

Enable PowerShell Remoting on this machine (configures WinRM)

Enable-PSRemoting -Force

Run a command on a remote machine

Invoke-Command -ComputerName Server01 -ScriptBlock { Get-Process }

Open an interactive remote session

Enter-PSSession -ComputerName Server01

Exit an interactive remote session

Exit-PSSession

Check the current PowerShell version

$PSVersionTable.PSVersion

FAQ