Loading...
Loading...
PowerShell Windows patterns. Critical pitfalls, operator syntax, error handling.
npx skill4agent add vudovn/antigravity-kit powershell-windowsCritical patterns and pitfalls for Windows PowerShell.
| ❌ Wrong | ✅ Correct |
|---|---|
| |
| |
| Purpose | ❌ Don't Use | ✅ Use |
|---|---|---|
| Success | ✅ ✓ | [OK] [+] |
| Error | ❌ ✗ 🔴 | [!] [X] |
| Warning | ⚠️ 🟡 | [*] [WARN] |
| Info | ℹ️ 🔵 | [i] [INFO] |
| Progress | ⏳ | [...] |
| ❌ Wrong | ✅ Correct |
|---|---|
| |
| |
| ❌ Wrong | ✅ Correct |
|---|---|
| Store in variable first |
$value = $obj.prop.sub
Write-Output "Value: $value"| Value | Use |
|---|---|
| Stop | Development (fail fast) |
| Continue | Production scripts |
| SilentlyContinue | When errors expected |
| Pattern | Use |
|---|---|
| Literal path | |
| Variable path | |
| Relative | |
| Operation | Syntax |
|---|---|
| Empty array | |
| Add item | |
| ArrayList add | `$list.Add($item) |
| ❌ Wrong | ✅ Correct |
|---|---|
| |
-Depth| Operation | Pattern |
|---|---|
| Read | `Get-Content "file.json" -Raw |
| Write | `$data |
| Error Message | Cause | Fix |
|---|---|---|
| "parameter 'or'" | Missing parentheses | Wrap cmdlets in () |
| "Unexpected token" | Unicode character | Use ASCII only |
| "Cannot find property" | Null object | Check null first |
| "Cannot convert" | Type mismatch | Use .ToString() |
# Strict mode
Set-StrictMode -Version Latest
$ErrorActionPreference = "Continue"
# Paths
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
# Main
try {
# Logic here
Write-Output "[OK] Done"
exit 0
}
catch {
Write-Warning "Error: $_"
exit 1
}Remember: PowerShell has unique syntax rules. Parentheses, ASCII-only, and null checks are non-negotiable.