powershell-windows
PowerShell Windows patterns. Critical pitfalls, operator syntax, error handling.
Author
Category
Development ToolsInstall
Download and extract to your skills directory
Copy command and send to OpenClaw for auto-install:
PowerShell Windows Script Standards
Help AI agents write scripts that follow Windows PowerShell best practices—master key syntax rules and avoid common pitfalls.
Applicable Scenarios
Core Functions
-Depth parameter when converting to JSON; performing null checks before accessing empty objects; and using Join-Path for file paths instead of string concatenation.Common Questions
Why do PowerShell logical operators need parentheses?
PowerShell requires that when using logical operators such as -or and -and, each cmdlet call must be wrapped in parentheses. Incorrect example: if (Test-Path "a" -or Test-Path "b"). Correct form: if ((Test-Path "a") -or (Test-Path "b")). Without parentheses, the parser may treat the operator as a parameter to the cmdlet.
Why does ConvertTo-Json output incomplete results?
By default, ConvertTo-Json has a depth limit of 2. Nested objects beyond two levels are truncated and displayed with ellipses. The solution is to always specify the -Depth parameter: ConvertTo-Json -Depth 10. This is a common pitfall when handling configuration files and complex data structures such as API responses.
Can PowerShell scripts use Emoji characters?
Not recommended. PowerShell scripts should use only ASCII characters and avoid Unicode symbols such as ✅, ❌, and ⚠️. Reasons include: encoding issues may cause symbol display problems, some terminal environments may not support Unicode, and ASCII is more reliable in logs and remote execution scenarios. Prefer alternatives like [OK], [!], and [*].