powershell-windows

Enforce PowerShell best practices for operators, null checks, and error handling.

Updated Dec 22, 2025
One-click install
npx skills add https://github.com/alaminmain/DoorAuthServer --skill powershell-windows-alaminmain
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: powershell-windows
Source: https://github.com/alaminmain/DoorAuthServer/tree/main/.agent/skills/powershell-windows
Command: npx skills add https://github.com/alaminmain/DoorAuthServer --skill powershell-windows-alaminmain

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps Windows administrators and developers write robust PowerShell scripts by outlining critical patterns, common pitfalls, and best practices to avoid syntax mistakes and runtime errors.

Core Features & Use Cases

  • Operator syntax rules: Ensure proper grouping with parentheses when using logical operators to avoid precedence errors.
  • Null checks and error handling: Guidelines for null safety, Try/Catch blocks, and consistent error actions to improve reliability.
  • File paths and JSON: Use Join-Path for consistent path handling and specify -Depth for nested JSON to avoid data truncation.
  • Scripting hygiene: Enforce ASCII-only scripts, clear naming, and reusable templates for everyday admin tasks.
  • Use Case: Validate a directory, filter by file extension, and log structured results for auditing.

Quick Start

Apply these patterns to your Windows PowerShell scripts to reduce runtime errors. Start by auditing an existing script, then adjust operator usage, null checks, and error handling.

Frequently Asked Questions about powershell-windows

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

FAQPage Schema
How do I handle PowerShell operator precedence errors in logical expressions?

PowerShell operator precedence errors occur when cmdlets are not wrapped in parentheses within logical expressions. Grouping cmdlets explicitly forces the correct evaluation order and prevents unexpected runtime behavior in your scripts.

Why does PowerShell truncate nested JSON data when I use ConvertTo-Json?

PowerShell truncates nested JSON data when the default depth is exceeded during conversion. Specify the explicit -Depth parameter in ConvertTo-Json to ensure deeply nested objects are fully serialized without losing data.

What is the best way to check for null values in PowerShell scripts?

Null checks in PowerShell scripts require explicit comparison against $null, preferably placing $null on the left side of the operator. This avoids issues where an array or object might evaluate unexpectedly.

How do I safely construct file paths in PowerShell to avoid invalid path errors?

Safely construct file paths in PowerShell by using the Join-Path cmdlet instead of manual string concatenation. This ensures correct path separators and prevents invalid path errors across different Windows directory structures.

Does PowerShell error handling require Try Catch blocks for reliable automation?

PowerShell error handling requires Try Catch blocks for reliable automation. You should also set consistent ErrorAction preferences to control non-terminating errors and ensure scripts fail predictably during execution.

When should I enable Set-StrictMode in PowerShell scripts?

Enable Set-StrictMode in PowerShell scripts during development to catch uninitialized variables and invalid property references. This prevents silent failures and enforces coding hygiene for reliable Windows automation.