What problem does it solve?
Windows PowerShell scripting often suffers from fragile operator handling, non-ASCII characters, unsafe path handling, and inconsistent error management, leading to hard-to-maintain scripts. This skill provides a structured set of patterns to write robust, portable PowerShell scripts on Windows.
Core Features & Use Cases
- Operator syntax rules: always place cmdlets within parentheses when using logical operators to avoid precedence errors.
- ASCII-only scripting: enforce ASCII characters to maximize compatibility and reduce encoding issues.
- Null checks and safe access: promote explicit null checks before accessing properties or collection members to prevent runtime errors.
- Reliable error handling: provide guidance on using Try/Catch, error actions, and consistent exit codes.
- File and path handling: recommend Join-Path and safe path construction for cross-version scripts.
- JSON and data handling: specify proper Depth for ConvertTo-Json and robust parsing patterns.
- Script template: include a default template to start new scripts with strict mode and consistent structure.
Quick Start
Review a Windows PowerShell script and rewrite it to comply with the listed patterns: ensure parentheses around cmdlets with logical operators, ASCII-only content, explicit null checks, robust error handling, and safe path construction.