Add-Content
Append text to a file
Add-Content -Path .\notes.txt -Value 'Another line'
The cheat sheet
One-liners plus the why. Copy, paste, then open the page if the result looks wrong.
No commands match. Try fewer words, or ask for the one you need.
Add-Content
Append text to a file
Add-Content -Path .\notes.txt -Value 'Another line'
Join-Path
Build a path safely
Join-Path -Path .\docs -ChildPath 'notes.txt'
Set-Location
Change the current directory
Set-Location -Path .\docs
Get-FileHash
Check a file's hash (checksum)
Get-FileHash -Path .\installer.exe -Algorithm SHA256
Test-Path
Check whether a path exists
Test-Path -Path .\docs
Copy-Item
Copy a file or folder
Copy-Item -Path .\notes.txt -Destination .\backup\notes.txt
New-Item
Create a file or folder
New-Item -Path .\docs -ItemType Directory
Remove-Item
Delete a file or folder
Remove-Item -Path .\temp\old.log
Get-Item
Get one file, folder, or item
Get-Item -Path .\notes.txt
Get-ChildItem
List files in a folder
Get-ChildItem -Path .\docs
Move-Item
Move or rename by moving
Move-Item -Path .\notes.txt -Destination .\archive\notes.txt
Set-Content
Overwrite a text file
Set-Content -Path .\notes.txt -Value 'Hello'
Split-Path
Pull a folder or name out of a path
Split-Path -Path .\docs\notes.txt -Parent
Get-Content
Read a text file
Get-Content -Path .\notes.txt
Get-ItemProperty
Read item properties
Get-ItemProperty -Path .\notes.txt
Rename-Item
Rename a file or folder
Rename-Item -Path .\draft.txt -NewName final.txt
Get-Acl
See who can access a file or folder Windows only
(Get-Acl -Path .\docs).Access | Select-Object IdentityReference, FileSystemRights, AccessControlType
Out-File
Send output to a file
Get-ChildItem | Out-File -FilePath .\listing.txt
Get-Location
Show the current folder
Get-Location
Resolve-Path
Turn a relative path into a full path
Resolve-Path -Path .\docs
Expand-Archive
Unzip a file
Expand-Archive -Path .\docs.zip -DestinationPath .\docs-unzipped
Compress-Archive
Zip a folder or files
Compress-Archive -Path .\docs -DestinationPath .\docs.zip
Unblock-File
Allow a downloaded script to run Windows only
Unblock-File -Path .\script.ps1
Set-ExecutionPolicy
Allow scripts to run on this computer Windows only
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Get-Command
Find a cmdlet by name
Get-Command -Name *Item
Install-Module
Install a module from the PowerShell Gallery
Install-Module -Name ImportExcel -Scope CurrentUser
Get-Alias
List command aliases
Get-Alias -Name gci
Get-Help
Read help for a command
Get-Help Get-ChildItem -Full
Find-Module
Search the PowerShell Gallery
Find-Module -Tag Excel | Select-Object -First 10 Name, Version, Description
Get-History
See commands you ran earlier
Get-History -Count 20
Get-Module
See loaded and available modules
Get-Module -ListAvailable
Get-Member
See properties and methods on an object
Get-ChildItem | Get-Member
Get-ExecutionPolicy
See whether scripts are allowed to run Windows only
Get-ExecutionPolicy -List
Invoke-RestMethod
Call a JSON API
Invoke-RestMethod -Uri 'https://example.com'
Invoke-WebRequest
Fetch a web page or file
Invoke-WebRequest -Uri 'https://example.com' -UseBasicParsing
Get-NetTCPConnection
Find which program is using a port Windows only
Get-NetTCPConnection -LocalPort 8080 | Select-Object LocalAddress, LocalPort, State, OwningProcess
Get-NetIPAddress
List local IP addresses Windows only
Get-NetIPAddress -AddressFamily IPv4 | Select-Object InterfaceAlias, IPAddress
Resolve-DnsName
Look up a DNS name Windows only
Resolve-DnsName -Name example.com
Test-Connection
Ping a host
Test-Connection -ComputerName 1.1.1.1 -Count 2
Test-NetConnection
Test a TCP port or route Windows only
Test-NetConnection -ComputerName example.com -Port 443
Get-Volume
Check free disk space Windows only
Get-Volume | Select-Object DriveLetter, FileSystemLabel, SizeRemaining, Size
Clear-Host
Clear the screen
Clear-Host
Get-Date
Get the current date and time
Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
Get-PSDrive
List drives PowerShell can see
Get-PSDrive
Get-LocalUser
List local user accounts Windows only
Get-LocalUser | Select-Object Name, Enabled, LastLogon
Get-Process
List running processes
Get-Process | Sort-Object CPU -Descending | Select-Object -First 10
Get-Service
List Windows services Windows only
Get-Service | Where-Object Status -eq 'Running'
Start-Process
Open a file or start a program
Start-Process -FilePath .\notes.txt
Start-Sleep
Pause for N seconds
Start-Sleep -Seconds 5
Get-CimInstance
Query system details (WMI/CIM) Windows only
Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object Caption, Version, LastBootUpTime
Get-WinEvent
Read the Windows event log Windows only
Get-WinEvent -LogName System -MaxEvents 20
Start-Transcript
Record the session to a log file
Start-Transcript -Path (Join-Path $env:TEMP 'ps-transcript.txt')
Restart-Service
Restart a Windows service Windows only Admin
Restart-Service -Name Spooler -WhatIf
Restart-Computer
Restart the computer Windows only
Restart-Computer -WhatIf
Invoke-Command
Run a command on another computer
Invoke-Command -ComputerName PC01 -ScriptBlock { Get-Service -Name Spooler }
Start-Service
Start a Windows service Windows only Admin
Start-Service -Name Spooler
Stop-Process
Stop a process
Stop-Process -Name notepad -WhatIf
Stop-Service
Stop a Windows service Windows only Admin
Stop-Service -Name Spooler -WhatIf
Get-ComputerInfo
Summarize this computer Windows only
Get-ComputerInfo | Select-Object CsName, WindowsVersion, OsArchitecture
Measure-Command
Time how long a command takes
Measure-Command { Get-ChildItem -Path .\docs -Recurse }
Out-GridView
Browse and filter results in a window Windows only
Get-Process | Out-GridView
Compare-Object
Compare two lists
Compare-Object -ReferenceObject $old -DifferenceObject $new
Set-Clipboard
Copy output to the clipboard
Get-ChildItem -Name | Set-Clipboard
Measure-Object
Count, sum, or average
Get-ChildItem -File | Measure-Object -Property Length -Sum
Where-Object
Filter objects in the pipeline
Get-ChildItem | Where-Object { $_.Extension -eq '.md' }
Group-Object
Group objects by a property
Get-ChildItem -File | Group-Object -Property Extension
ConvertFrom-Json
Parse JSON text
Get-Content -Path .\data.json -Raw | ConvertFrom-Json
Select-Object
Pick properties or the first N objects
Get-ChildItem | Select-Object -First 5 Name, Length
Write-Output
Print a message (Write-Output vs Write-Host)
Write-Output 'Backup finished'
Import-Csv
Read a CSV file as objects
Import-Csv -Path .\people.csv
Get-Clipboard
Read what is on the clipboard
Get-Clipboard
ForEach-Object
Run a block on each object
Get-ChildItem -File | ForEach-Object { $_.Name }
Select-String
Search text like grep
Select-String -Path .\docs\*.md -Pattern 'TODO'
Format-List
Show objects as a list
Get-Item -Path .\notes.txt | Format-List *
Format-Table
Show objects as a table
Get-ChildItem | Format-Table Name, Length -AutoSize
Sort-Object
Sort pipeline objects
Get-ChildItem | Sort-Object -Property Length -Descending
ConvertTo-Json
Turn objects into JSON
Get-ChildItem -File | Select-Object Name, Length | ConvertTo-Json
ConvertTo-Html
Turn results into an HTML report
Get-Service | ConvertTo-Html -Property Name, Status -Title 'Services' | Out-File -FilePath .\services.html
Export-Csv
Write objects to a CSV file
Get-ChildItem -File | Select-Object Name, Length | Export-Csv -Path .\files.csv -NoTypeInformation