Home › PowerShell › PowerShell scripts and modules CLAUDE.md

PowerShell scripts and modules CLAUDE.md

CLAUDE.md for PowerShell 7 scripts and modules: advanced functions, strict error handling, ShouldProcess for changes, PSScriptAnalyzer, and Pester tests.

Claude Code (CLAUDE.md)PowerShell

How to use

Save this as CLAUDE.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

Note: Review and test before use. Provided as is, without warranty. See Terms.

CLAUDE.mdDownload  
# CLAUDE.md: PowerShell

## Commands
- Lint: `Invoke-ScriptAnalyzer -Path . -Recurse -Settings ./PSScriptAnalyzerSettings.psd1` (use the defaults if no settings file)
- Test: `Invoke-Pester -Path ./tests -Output Detailed`
- Target PowerShell 7 (`pwsh`) unless `#Requires -Version 5.1` or the README says Windows PowerShell must be supported. Check before using 7-only syntax (`??`, `?.`, ternary, `ForEach-Object -Parallel`).

## Writing code
- Every function is an advanced function: `[CmdletBinding()]`, an approved verb (`Get-Verb`) in `Verb-Noun` form, typed `param()` with `[Parameter(Mandatory)]` and validation attributes (`[ValidateSet()]`, `[ValidateNotNullOrEmpty()]`).
- Start scripts with `#Requires` lines, `Set-StrictMode -Version Latest` and `$ErrorActionPreference = 'Stop'`. Use `try/catch` around external calls and rethrow with context; never swallow errors silently.
- Functions that change state (files, services, registry, cloud resources) declare `SupportsShouldProcess` and wrap the change in `if ($PSCmdlet.ShouldProcess($target, $action))`, so `-WhatIf` and `-Confirm` work.
- Output objects (`[pscustomobject]`), not formatted text. No `Write-Host` for data; use `Write-Verbose`, `Write-Information`, `Write-Warning`. `Format-*` only at the very end of interactive use.
- No aliases (`%`, `?`, `ls`, `gci`) or positional parameters in committed code. Use splatting for calls with more than three parameters.
- Paths with `Join-Path` and `-LiteralPath` for user-supplied paths; never build paths by string concatenation.
- Secrets: `[SecureString]`/`PSCredential` parameters or the SecretManagement module; never hardcode or print credentials. Don't use `Invoke-Expression` on input.
- Modules: one function per file under `Public/` and `Private/`, exported explicitly in the `.psd1` (`FunctionsToExport`, no wildcards). Comment-based help (`.SYNOPSIS`, `.EXAMPLE`) on every public function.

## Done when
ScriptAnalyzer reports no errors or warnings for changed files and Pester tests (with mocks for external commands) pass. Never run destructive commands against real systems to test.

More: all PowerShell rules · all Claude Code (CLAUDE.md) rules

Related rules

AWS CDK (TypeScript) CLAUDE.md

CLAUDE.md for AWS CDK v2 apps in TypeScript: constructs, least-privilege grants, snapshot tests, and safe deploys.

Claude Code (CLAUDE.md)AWS CDK

Kubernetes & Helm CLAUDE.md

CLAUDE.md for Kubernetes manifests and Helm 3 charts: resources, probes, security context, and safe rollouts.

Claude Code (CLAUDE.md)Kubernetes / Helm

Pulumi (TypeScript) CLAUDE.md

CLAUDE.md for Pulumi infrastructure in TypeScript: stacks and config, secrets, component resources, and preview-only rules.

Claude Code (CLAUDE.md)Pulumi

Ansible Windsurf rules

Windsurf rules for Ansible playbooks and roles: FQCN modules, idempotency, check mode, vault secrets, and ansible-lint.

WindsurfAnsible

Azure Functions AGENTS.md

AGENTS.md for Azure Functions apps: current programming models, local Core Tools runs, idempotent triggers, managed identity, configuration, and Durable Functions rules.

AGENTS.mdAzure (Functions / Bicep)

Bash and shell scripts Windsurf rules

Windsurf rules for Bash scripts: strict mode, quoting, shellcheck and shfmt, safe temp files and cleanup traps, argument parsing, portability, and bats tests.

WindsurfBash / shell scripts

Get the best new AI prompts every week

One short email a week: the best new prompts and rules for ChatGPT, Claude, Gemini, Midjourney, Cursor and more, plus what changed in the tools. Free, unsubscribe anytime.

Finishes on our newsletter page at beehiiv (opens in a new tab). Or subscribe directly.