PowerShell
Finding commands and help, files and processes, filtering objects, environment variables and web requests.
Getting around
Find a command
Get-Command *<keyword>*
Help with examples
Get-Help <cmdlet> -Examples
What properties an object has
Get-Process | Get-MemberPowerShell version
$PSVersionTableFiles
List files recursively by mask
Get-ChildItem -Recurse -Filter *.logSearch text in files (grep)
Select-String -Path *.log -Pattern '<pattern>'
Follow a log file (tail -f)
Get-Content app.log -Wait -Tail 50Largest files in a folderadvanced
Get-ChildItem -Recurse -File | Sort-Object Length -Descending | Select-Object -First 10 FullName, LengthProcesses, services, network
Top processes by CPU
Get-Process | Sort-Object CPU -Descending | Select-Object -First 10Stop a process by name
Stop-Process -Name <name> -Force
Who listens on a port
Get-NetTCPConnection -LocalPort <port> | Select-Object LocalPort, State, OwningProcess
Is a TCP port reachable
Test-NetConnection <host> -Port <port>
Restart a Windows service
Restart-Service -Name <windows_service>
Data and web
Filter and select objects
Get-Service | Where-Object Status -eq 'Running' | Select-Object Name, DisplayNameCall a JSON API (parsed automatically)
Invoke-RestMethod <url>
Export objects to CSV
Get-Process | Export-Csv processes.csv -NoTypeInformationSet an environment variable for the session
$env:<env_var> = 'value'
Allow running local scriptsadvanced
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned