U

Ultimate Powershell Windows

Streamline your workflow with this powershell, windows, patterns, critical. Includes structured workflows, validation checks, and reusable patterns for development.

SkillClipticsdevelopmentv1.0.0MIT
0 views0 copies

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

WrongCorrectWhy
if ($a -eq $b) {}if ($a -eq $b) { }Braces on same line
$array.Count -gt 0($array.Count) -gt 0Parentheses around property access
"text" + $var + "text""text ${var} text"String interpolation
$result = cmd /arg$result = & cmd /argCall 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

ParameterTypeDefaultDescription
PSVersionstring"7.0"Minimum PowerShell version
ErrorActionPreferencestring"Stop"Error handling: Stop, Continue, SilentlyContinue
ExecutionPolicystring"RemoteSigned"Script execution policy
OutputEncodingstring"UTF8"Output text encoding
ProgressPreferencestring"SilentlyContinue"Progress bar display

Best Practices

  1. Always use $ErrorActionPreference = 'Stop' — by default, PowerShell continues after non-terminating errors; Stop makes all errors halt execution like other languages expect.

  2. Use [CmdletBinding()] and named parameters — this enables -Verbose, -Debug, and -ErrorAction on your functions, and validates parameter input automatically.

  3. Wrap executable calls with the call operator & — use & program.exe --arg instead of just program.exe --arg; the call operator handles paths with spaces and ensures proper execution.

  4. Use Test-Path before file operations — always check if paths exist before reading, writing, or deleting; PowerShell file errors can be cryptic without pre-validation.

  5. Use try/catch/finally for all critical operations — catch specific exception types when possible: catch [System.IO.IOException] is more precise than a generic catch.

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.

Community

Reviews

Write a review

No reviews yet. Be the first to review this template!

Similar Templates