PowerShell
Executive Summary
PowerShell is a Windows automation and administration shell used for system management, enumeration, file handling, networking, logging, and security operations.
This cheatsheet focuses on quick command lookup for common administrative and security workflows.
Help and Discovery
Show help:
Show examples:
Search commands:
Show command syntax:
Show PowerShell version:
System Information
Computer information:
Operating system details:
Hostname:
Current user:
Environment variables:
Files and Directories
List files:
List hidden files:
Recursive listing:
Read file:
Search file content:
Copy file:
Move file:
Delete file:
Processes
List processes:
Search process:
Stop process by name:
Stop process by PID:
Show process command lines:
Services
List services:
Running services:
Service details:
Start service:
Stop service:
Users and Groups
Current user:
Local users:
Local groups:
Local administrators:
Current user groups:
Current user privileges:
Networking
Show IP addresses:
Show routes:
Show TCP connections:
Show listening TCP ports:
Test port:
DNS lookup:
Show DNS cache:
File Downloads
Download file:
Download with basic parsing:
Alternative WebClient download:
Download string:
File Uploads
Upload file with WebClient:
Upload with Invoke-WebRequest:
Encoding and Hashing
File hash:
Base64 encode string:
Base64 decode string:
Base64 decode file:
Event Logs
List event logs:
Recent Security events:
Logon events:
Failed logons:
Events from last 24 hours:
$Start = (Get-Date).AddHours(-24)
Get-WinEvent -FilterHashtable @{LogName="Security"; StartTime=$Start}
Registry
Query key:
Search registry path:
Create value:
New-ItemProperty -Path "HKCU:\Software\Test" -Name "Name" -Value "Value" -PropertyType String -Force
Delete value:
Remote Management
Enable PowerShell remoting:
Create remote session:
Run remote command:
Copy file to session:
Copy file from session:
Useful One-Liners
Find files containing keyword:
Find recently modified files:
Get-ChildItem C:\Users -Recurse -ErrorAction SilentlyContinue | Where-Object {$_.LastWriteTime -gt (Get-Date).AddDays(-1)}
List startup Run keys:
Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Run"
Show antivirus products:
Notes
- PowerShell activity is often logged by defenders.
Invoke-WebRequest,DownloadString, and encoded commands are high-signal detection points.- Prefer clear administrative use and documented workflows.
- Use
Get-CimInstanceover olderGet-WmiObjectwhen available.