Terminal
Powershell
Intermediate
PowerShell Cheat Sheet
PowerShell essentials for QA engineers. Cmdlets, pipelines, scripting, and automation on Windows.
PowerShell for QAs
Navigation
Get-Location # pwd equivalent
Set-Location tests/ # cd equivalent
Get-ChildItem # ls/dir equivalent
Get-ChildItem -Recurse # ls -R equivalent
Aliases (familiar shortcuts)
pwd # Get-Location
cd # Set-Location
ls # Get-ChildItem
cp # Copy-Item
mv # Move-Item
rm # Remove-Item
cat # Get-Content
echo # Write-Output
cls # Clear-Host
Files & Content
New-Item -ItemType File test.ps1 # Create file
New-Item -ItemType Directory test-suite # Create folder
Get-Content test.log # Read file
Get-Content test.log -Tail 20 # Last 20 lines
Get-Content test.log -Wait # Follow live (like tail -f)
Set-Content results.txt "PASSED" # Write to file
Add-Content results.txt "Line 2" # Append to file
Searching
Select-String "ERROR" test.log # grep equivalent
Select-String "login" tests/*.py -Recurse # Recursive search
Get-ChildItem -Recurse -Filter "*.py" # Find files
Get-ChildItem -Recurse | Where-Object {$_.Length -gt 1MB} # Large files
Running Tests
python -m pytest tests/
npx playwright test
dotnet test
Invoke-Pester # PowerShell testing framework
Pipelines (PowerShell's superpower)
# Get processes using lots of memory
Get-Process | Sort-Object CPU -Descending | Select-Object -First 10
# Find failed test results
Get-Content test-results.xml | Select-String "failure"
# Count test files
(Get-ChildItem tests/ -Recurse -Filter "*.py").Count
# Kill all Chrome processes
Get-Process chrome | Stop-Process -Force
Variables & Scripting
$baseUrl = "http://localhost:3000"
$env:BASE_URL = "http://localhost:3000" # Environment variable
# Simple test script
$results = Invoke-WebRequest -Uri "$baseUrl/api/health"
if ($results.StatusCode -eq 200) {
Write-Host "Health check passed" -ForegroundColor Green
} else {
Write-Host "Health check FAILED" -ForegroundColor Red
}
API Testing with PowerShell
# GET request
$response = Invoke-RestMethod -Uri "https://api.example.com/users"
$response | Format-Table
# POST request
$body = @{ email = "test@example.com"; password = "test123" } | ConvertTo-Json
Invoke-RestMethod -Uri "https://api.example.com/login" -Method POST -Body $body -ContentType "application/json"
Useful Commands
| Command | Purpose |
|---|---|
Get-Help cmdlet |
Get help on any command |
Get-Command *test* |
Find commands with "test" |
$PSVersionTable |
PowerShell version info |
Test-Connection google.com |
Ping equivalent |
Measure-Command { script } |
Time a command |