Ultimate Powershell Windows
Streamline your workflow with this powershell, windows, patterns, critical. Includes structured workflows, validation checks, and reusable patterns for development.
PowerShell Windows Development Skill
A Claude Code skill for Windows automation with PowerShell — covering cmdlet patterns, pipeline operations, Active Directory management, registry operations, and Windows-specific scripting best practices.
When to Use This Skill
Choose this skill when:
- Automating Windows system administration tasks
- Writing PowerShell scripts for deployment and configuration
- Managing Active Directory, IIS, or Windows services
- Working with the Windows registry and file system
- Building CI/CD scripts for Windows environments
- Debugging PowerShell syntax and operator issues
Consider alternatives when:
- You need cross-platform shell scripts (use Bash)
- You need Linux system administration (use a Linux shell skill)
- You need .NET application development (use a C# skill)
Quick Start
# Check PowerShell version $PSVersionTable.PSVersion # Run a script .\script.ps1 # Set execution policy (required for scripts) Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
# Production-ready script template #Requires -Version 7.0 [CmdletBinding()] param( [Parameter(Mandatory)] [string]$Environment, [ValidateSet('Deploy', 'Rollback', 'Status')] [string]$Action = 'Status' ) $ErrorActionPreference = 'Stop' try { Write-Host "Running $Action for $Environment" # Script logic here } catch { Write-Error "Failed: $_" exit 1 } finally { Write-Host "Script completed" }
Core Concepts
Critical Syntax Rules
| Wrong | Correct | Why |
|---|---|---|
if ($a -eq $b) {} | if ($a -eq $b) { } | Braces on same line |
$array.Count -gt 0 | ($array.Count) -gt 0 | Parentheses around property access |
"text" + $var + "text" | "text ${var} text" | String interpolation |
$result = cmd /arg | $result = & cmd /arg | Call operator for executables |
Pipeline Operations
# Filter, transform, sort Get-Process | Where-Object { $_.WorkingSet64 -gt 100MB } | Sort-Object WorkingSet64 -Descending | Select-Object Name, @{N='Memory(MB)'; E={[math]::Round($_.WorkingSet64/1MB,2)}} | Format-Table -AutoSize # Parallel processing $servers = @('srv1', 'srv2', 'srv3') $servers | ForEach-Object -Parallel { Test-Connection -ComputerName $_ -Count 1 -Quiet } -ThrottleLimit 5
Windows Management
# Service management Get-Service -Name 'MyService' | Restart-Service -Force New-Service -Name 'MyApp' -BinaryPathName 'C:\app\myapp.exe' -StartupType Automatic # Registry operations Get-ItemProperty -Path 'HKLM:\SOFTWARE\MyApp' -Name 'Version' Set-ItemProperty -Path 'HKLM:\SOFTWARE\MyApp' -Name 'Version' -Value '2.0' # Scheduled tasks $trigger = New-ScheduledTaskTrigger -Daily -At '2:00AM' $action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-File C:\scripts\backup.ps1' Register-ScheduledTask -TaskName 'NightlyBackup' -Trigger $trigger -Action $action
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
PSVersion | string | "7.0" | Minimum PowerShell version |
ErrorActionPreference | string | "Stop" | Error handling: Stop, Continue, SilentlyContinue |
ExecutionPolicy | string | "RemoteSigned" | Script execution policy |
OutputEncoding | string | "UTF8" | Output text encoding |
ProgressPreference | string | "SilentlyContinue" | Progress bar display |
Best Practices
-
Always use
$ErrorActionPreference = 'Stop'— by default, PowerShell continues after non-terminating errors;Stopmakes all errors halt execution like other languages expect. -
Use
[CmdletBinding()]and named parameters — this enables-Verbose,-Debug, and-ErrorActionon your functions, and validates parameter input automatically. -
Wrap executable calls with the call operator
&— use& program.exe --arginstead of justprogram.exe --arg; the call operator handles paths with spaces and ensures proper execution. -
Use
Test-Pathbefore file operations — always check if paths exist before reading, writing, or deleting; PowerShell file errors can be cryptic without pre-validation. -
Use
try/catch/finallyfor all critical operations — catch specific exception types when possible:catch [System.IO.IOException]is more precise than a genericcatch.
Common Issues
Scripts won't run due to execution policy — Run Set-ExecutionPolicy RemoteSigned -Scope CurrentUser to allow local scripts. Don't use Unrestricted in production as it allows all scripts.
Comparison operators don't work as expected — PowerShell uses -eq, -ne, -gt, -lt instead of ==, !=, >, <. The familiar operators are for redirection and will create files instead of comparing.
String variables don't expand in single quotes — Use double quotes "Hello $name" for variable expansion; single quotes 'Hello $name' are literal strings. This is the opposite of some other languages.
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Full-Stack Code Reviewer
Comprehensive code review skill that checks for security vulnerabilities, performance issues, accessibility, and best practices across frontend and backend code.
Test Suite Generator
Generates comprehensive test suites with unit tests, integration tests, and edge cases. Supports Jest, Vitest, Pytest, and Go testing.
Pro Architecture Workspace
Battle-tested skill for architectural, decision, making, framework. Includes structured workflows, validation checks, and reusable patterns for development.