powershell-windows

Provides PowerShell syntax rules, pitfalls, and error handling patterns for Windows scripting.

2|Updated May 30, 2026
One-click install
npx skills add https://github.com/virahitvin8/crafty-gis --skill powershell-windows-virahitvin8
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: powershell-windows
Source: https://github.com/virahitvin8/crafty-gis/tree/main/GIT_STAR/.agent/skills/powershell-windows
Command: npx skills add https://github.com/virahitvin8/crafty-gis --skill powershell-windows-virahitvin8

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing PowerShell scripts on Windows often leads to subtle syntax errors, such as missing parentheses around cmdlet calls in logical expressions, Unicode characters breaking scripts, and null reference failures. This Skill codifies the critical rules and patterns so scripts work correctly the first time. ## Core Features & Use Cases - Operator Syntax Rules: Enforces parentheses around cmdlet calls when using -or and -and logical operators. - Safe Scripting Patterns: Covers ASCII-only output conventions, null checks before property access, and string interpolation best practices. - JSON and Error Handling: Mandates ConvertTo-Json -Depth for nested objects and provides try/catch templates with ErrorActionPreference guidance. - Use Case: When writing a Windows automation script that reads a JSON config, checks file paths, and logs status messages, apply these patterns to avoid the common "parameter 'or'" and "Cannot find property" errors. ## Quick Start Review my PowerShell script for Windows and fix any syntax, null-check, or JSON handling issues using the standard patterns.

Frequently Asked Questions about powershell-windows

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix the PowerShell "parameter 'or'" error?

The "parameter 'or'" error occurs when cmdlet calls are not wrapped in parentheses inside logical expressions. Write if ((Test-Path "a") -or (Test-Path "b")) so each cmdlet result is evaluated before the -or operator is applied.

How do I convert nested objects to JSON in PowerShell?

Use ConvertTo-Json with the -Depth parameter, for example $data | ConvertTo-Json -Depth 10. Without -Depth, PowerShell truncates nested objects beyond the default depth of 2, producing incomplete JSON output.

Why does my PowerShell script fail with unexpected token errors?

Unexpected token errors are commonly caused by Unicode characters such as emoji or smart quotes in the script. Replace them with ASCII-only markers like [OK], [!], or [INFO] to keep scripts parseable across editors and consoles.

How do I safely check for null before accessing properties in PowerShell?

Guard property access with a null check first, such as if ($array -and $array.Count -gt 0). Accessing .Count or .Length on a null variable throws a runtime error, so always validate the object exists before dereferencing it.

When should I use Stop versus Continue for ErrorActionPreference?

Use Stop during development so errors fail fast and surface immediately. Use Continue in production scripts where partial failures are acceptable, and SilentlyContinue only when errors are expected and can be safely ignored.