powershell-windows

PowerShell Windows patterns. Critical pitfalls, operator syntax, error handling.

Author

Install

Hot:2

Download and extract to your skills directory

Copy command and send to OpenClaw for auto-install:

Download and install this skill https://openskills.cc/api/download?slug=sickn33-skills-powershell-windows&locale=en&source=copy

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

  • Windows Automation Script Development: Write reliable scripts for Windows server management, batch file operations, and system maintenance tasks, preventing execution failures caused by syntax errors.
  • PowerShell Script Debugging and Optimization: Quickly locate and fix common script issues, such as missing parentheses around logical operators, truncated JSON output, and null reference errors.
  • Cross-Team Script Standardization: Provide a unified PowerShell coding standard for the team to ensure script readability, maintainability, and cross-platform compatibility.
  • Core Functions

  • Syntax Rule Checking: Enforce PowerShell-specific syntax rules, including that logical operators must wrap cmdlet calls in parentheses; scripts must use only ASCII characters (no Emoji/Unicode); and proper string interpolation formatting.
  • Common Error Prevention: Automatically identify and warn developers to avoid typical traps, such as requiring the -Depth parameter when converting to JSON; performing null checks before accessing empty objects; and using Join-Path for file paths instead of string concatenation.
  • Code Template Generation: Provide script templates that align with best practices, including strict mode settings, an error-handling framework, and path-handling conventions—ensuring that new projects follow industry standards from the start.
  • 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 [*].