Back to Skills

powershell-windows

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

40,726stars6,569forksUpdated 6/15/2026

Security Assessment

Safe(100/100)
Security Score100/100

About powershell-windows

The powershell-windows skill provides essential patterns and best practices for writing robust PowerShell scripts on Windows systems. It addresses common pitfalls that developers encounter when working with PowerShell's unique syntax, particularly around operator usage, string handling, and error management. This skill serves as a quick reference guide to avoid syntax errors and runtime failures that are specific to the PowerShell environment.

The skill covers critical areas including proper operator syntax with required parentheses around cmdlet calls, ASCII-only character restrictions to avoid encoding issues, null-safe object access patterns, string interpolation best practices, and comprehensive error handling strategies. It also provides guidance on file path operations, array manipulations, JSON serialization with proper depth handling, and common error patterns with their solutions.

This skill is designed for developers and system administrators who write PowerShell scripts for Windows automation, configuration management, or system administration tasks. It is particularly valuable for those transitioning from other scripting languages who may not be familiar with PowerShell's syntax quirks, as well as experienced PowerShell users who want to ensure their scripts follow best practices and avoid common runtime errors.

FAQ

Why do I need parentheses around cmdlets when using logical operators?

PowerShell requires each cmdlet call to be wrapped in parentheses when combining them with logical operators like -or and -and. Without parentheses, PowerShell interprets the operator as a parameter to the cmdlet, causing syntax errors. For example, use 'if ((Test-Path "a") -or (Test-Path "b"))' instead of 'if (Test-Path "a" -or Test-Path "b")'.

Can I use emoji or Unicode characters in my PowerShell scripts?

No, you should avoid Unicode characters and emoji in PowerShell scripts as they can cause encoding issues and unexpected behavior. Use ASCII alternatives instead: [OK] or [+] for success, [!] or [X] for errors, [*] or [WARN] for warnings, and [i] or [INFO] for informational messages.

What's the correct way to handle JSON in PowerShell?

Always specify the -Depth parameter when using ConvertTo-Json to avoid truncation of nested objects. Use 'ConvertTo-Json -Depth 10' as a safe default. When reading JSON files, use 'Get-Content "file.json" -Raw | ConvertFrom-Json', and when writing, use '$data | ConvertTo-Json -Depth 10 | Out-File "file.json" -Encoding UTF8'.

How should I handle errors in production PowerShell scripts?

Use 'Set-StrictMode -Version Latest' and set '$ErrorActionPreference = "Continue"' for production scripts to allow graceful error handling. Wrap main logic in try/catch blocks, avoid returning inside the try block, use finally for cleanup operations, and return after the try/catch structure is complete.

What's the safest way to work with file paths in PowerShell?

Always use Join-Path for constructing file paths to ensure cross-platform compatibility and proper path separator handling. For example, use 'Join-Path $env:USERPROFILE "file.txt"' instead of string concatenation. This prevents path-related errors and makes scripts more portable.

Install powershell-windows

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill