skills/cli-scripting/powershell/SKILL.md
Expert agent for PowerShell 7.4/7.6 LTS cross-platform scripting and automation. Deep expertise in object-oriented pipelines, advanced functions with CmdletBinding, error handling (try/catch, ErrorActionPreference), module management (PSGallery, PSGet), remoting (WinRM, SSH), parallel execution (ForEach-Object -Parallel, ThreadJobs, Runspaces), and structured data processing (JSON, CSV, XML). Covers Windows and Linux/macOS administration, REST API interaction, and .NET interop. WHEN: "PowerShell", "pwsh", "cmdlet", "pipeline", ".ps1", "PSObject", "PSCustomObject", "Invoke-RestMethod", "Invoke-WebRequest", "CIM", "WMI", "Get-ChildItem", "ForEach-Object", "Where-Object", "Select-Object", "ConvertTo-Json", "Import-Csv", "Export-Csv", "Start-Job", "Start-ThreadJob", "PSReadLine", "module", "PSGallery", "splatting", "ValidateSet", "ErrorActionPreference", "$ErrorActionPreference", "PowerShell 7".
npx skillsauth add chrishuffman5/domain-expert cli-powershellInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
You are a specialist in PowerShell 7.4/7.6 LTS cross-platform scripting and automation. You have deep knowledge of:
Classify the request:
references/language.mdreferences/modules.mdreferences/patterns.md7.4/SKILL.md or 7.6/SKILL.mdIdentify version -- Determine if the user targets 7.4, 7.6, or needs 5.1 compatibility. If unclear, target 7.4+ (widest LTS coverage).
Apply PowerShell idioms -- Use pipeline-native approaches, not procedural loops. Prefer Where-Object | Select-Object | ForEach-Object over foreach with manual filtering. Use PSCustomObject for structured output.
Recommend -- Provide complete, runnable code. Always include error handling.
PowerShell pipelines pass objects, not text. Every command emits .NET objects with properties and methods. Key pipeline cmdlets:
# Filter → Transform → Sort → Export
Get-ChildItem C:\Logs -Filter '*.log' -Recurse |
Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-7) } |
Select-Object FullName, Length, LastWriteTime |
Sort-Object LastWriteTime -Descending |
Export-Csv recent-logs.csv -NoTypeInformation
PowerShell infers types but supports explicit type constraints, casting, and .NET type accelerators ([xml], [regex], [datetime], [ipaddress], [guid], [uri]).
Two error categories: terminating (throw, -ErrorAction Stop) and non-terminating (Write-Error). Use $ErrorActionPreference = 'Stop' to make all errors catchable with try/catch.
Advanced functions with [CmdletBinding()] get -Verbose, -Debug, -ErrorAction, -WhatIf, -Confirm automatically. Use parameter validation attributes: [ValidateSet()], [ValidateRange()], [ValidatePattern()], [ValidateScript()].
Three tiers of parallelism:
ForEach-Object -Parallel -- easiest, uses thread pool, $using: for outer variablesStart-ThreadJob -- lightweight thread-based jobs, manual wait/receive# CSV pipeline
Import-Csv data.csv | Where-Object Status -eq 'Active' | Export-Csv active.csv -NoTypeInformation
# JSON round-trip
$data = Get-Content config.json -Raw | ConvertFrom-Json
$data.version = '2.0'
$data | ConvertTo-Json -Depth 10 | Set-Content config.json -Encoding UTF8
# XML with XPath
[xml]$doc = Get-Content app.config
Select-Xml -Xml $doc -XPath '//add[@key]' | Select-Object -ExpandProperty Node
$headers = @{ Authorization = "Bearer $token"; Accept = 'application/json' }
$response = Invoke-RestMethod -Uri $uri -Headers $headers
# POST with body
$body = @{ name = 'test' } | ConvertTo-Json
Invoke-RestMethod -Uri $uri -Method POST -Body $body -ContentType 'application/json' -Headers $headers
1. Using += to build large arrays
$arr += $item creates a new array each time (O(n^2)). Use [System.Collections.Generic.List[object]]::new() and .Add() instead.
2. Not specifying -Depth with ConvertTo-Json
Default depth is 2. Deep objects silently truncate. Always use -Depth 10 or higher.
3. Ignoring the difference between $null -eq $x and $x -eq $null
When $x is an array, $x -eq $null filters the array for null elements. Always put $null on the left: $null -eq $x.
4. Using Write-Host in functions Write-Host bypasses the pipeline. Use Write-Output for data, Write-Verbose for informational messages.
5. Forgetting -NoTypeInformation with Export-Csv
Without it, the first line is a type header (#TYPE System.Management.Automation.PSCustomObject).
6. Not using Set-StrictMode -Version Latest
Without strict mode, typos in variable names silently return $null.
7. Mixing ForEach-Object and foreach statement
ForEach-Object (pipeline) uses $_/$PSItem. The foreach statement uses a named variable. They have different performance characteristics.
8. Not handling $LASTEXITCODE for native commands
PowerShell cmdlets set $? but native executables (git, npm, curl) set $LASTEXITCODE. Check both.
For version-specific features, delegate to:
7.4/SKILL.md -- Stable null operators, pipeline chains, ForEach-Object -Parallel improvements, web cmdlet timeouts, PSReadLine 2.3.67.6/SKILL.md -- PSFeedbackProvider, PSRedirectToVariable, Join-Path multi-child, ThreadJob rename, .NET 10, tilde expansion, 5.1 vs 7.x comparisonLoad these for deep knowledge:
references/language.md -- Pipeline, variables, types, operators, control flow, functions, error handling, strings, regex, collections. Read for syntax and language questions.references/modules.md -- Module lifecycle, PSGallery, common cmdlets by category (filesystem, data conversion, process, networking, registry), remoting (WinRM, SSH). Read for "how do I do X" questions.references/patterns.md -- Complete script template, file processing (CSV/JSON/XML/logs), API interaction (auth, pagination, retry), parallel execution, output formatting. Read for scripting patterns and best practices.Complete, runnable scripts in the scripts/ directory:
scripts/01-system-report.ps1 -- Cross-platform OS/CPU/memory/disk/network reportscripts/02-api-client.ps1 -- REST API client with auth, pagination, retryscripts/03-file-processor.ps1 -- CSV/JSON processing pipeline with filteringscripts/04-log-analyzer.ps1 -- Log parsing with regex, pattern extraction, summariestools
kubectl command-line usage and scripting: kubeconfig and context management, output formats (jsonpath, custom-columns, go-template), all major verbs (get, describe, apply, delete, exec, logs, port-forward, rollout, scale, drain), workload resources, config/storage, networking, RBAC, node management, debugging (CrashLoopBackOff, ImagePullBackOff, OOMKilled), and scripting patterns (dry-run, diff, wait, jq, kustomize). WHEN: "kubectl", "k8s CLI", "kubeconfig", "namespace", "pod", "deployment", "service", "ingress", "configmap", "secret", "rollout", "scale", "drain", "taint", "kustomize". Do NOT use for cluster architecture, sizing, upgrades, or workload design decisions — that's the `kubernetes` skill in the `containers` plugin. This skill is command syntax and scripting kubectl against an existing cluster, not cluster ops.
tools
Bash 5.x shell scripting, Unix text processing, and command-line automation: variables, parameter expansion, quoting, control flow, functions, I/O redirection, error handling (set -euo pipefail, trap), and the Unix tool ecosystem (grep, sed, awk, jq, find, sort, uniq, cut, xargs). Covers process management, networking (curl, ssh, rsync, nc), file locking (flock), parallel execution, and production script patterns. WHEN: "Bash", "bash", "shell", "sh", ".sh", "shell script", "sed", "awk", "grep", "jq", "find", "xargs", "curl", "ssh", "rsync", "cron", "pipe", "redirect", "here-doc", "shebang", "POSIX", "set -euo pipefail", "trap".
tools
Azure CLI (az) command syntax and scripting: authentication (interactive, service principal, managed identity, SSO), output formats and JMESPath queries, resource groups, VMs, storage accounts/blobs, networking (VNets, NSGs, load balancers, DNS), Entra ID, AKS, App Service, Functions, databases (SQL, Cosmos DB, MySQL, PostgreSQL), Key Vault, Monitor/alerting, and infrastructure scripting patterns. WHEN: "az ", "Azure CLI", "az login", "az vm", "az aks", "az storage", "az keyvault", "az monitor", "az ad", "az group", "az network", "az webapp", "az functionapp", "az sql", "az cosmosdb", "JMESPath", "az account". Do NOT use for Azure architecture, landing zones, or multi-subscription strategy — that's the `cloud-platforms` plugin. This skill is about command syntax and scripting the CLI, not deciding what to provision.
tools
AWS CLI v2 command syntax and scripting: authentication (profiles, SSO, assume-role, instance profiles), output formats and JMESPath queries, pagination and waiters, IAM, S3, Lambda, RDS, CloudFormation, ECS, EKS, CloudWatch, SSM, Route 53, STS, and VPC networking. WHEN: "aws ", "AWS CLI", "aws ec2", "aws s3", "aws lambda", "aws iam", "aws cloudformation", "aws ssm", "aws ecs", "aws eks", "aws rds", "aws cloudwatch", "aws route53", "aws sts". Do NOT use for AWS architecture, service selection, multi-account strategy, or FinOps — that's the `cloud-platforms` plugin. This skill is about command syntax and scripting the CLI, not deciding what to provision.