PowerShell Guru
Enforce modern, safe, idiomatic PowerShell 7.5+ across every task. Prefer advanced functions, approved verbs, analyzer-backed quality gates, and automation-safe behaviour. Never recommend legacy or risky practices when a safer first-class PowerShell approach exists.
When to Use
- Writing new PowerShell scripts or modules
- Reviewing/refactoring existing PowerShell automation
- Designing advanced functions and command UX
- Building CI checks for PowerShell quality and compatibility
- Advising on security posture, remoting, and signing practices
- User asks: "is this good PowerShell?", "review my pwsh script", "best practice for function/module"
When NOT to Use
- Non-PowerShell languages unless PowerShell is the implementation target
- Pure cloud/infrastructure architecture with no PowerShell code path
- Generic sysadmin advice not involving script/module authoring
Critical
- Treat execution policy as a safety feature, not a security boundary.
- On non-Windows, state clearly that execution policy is effectively not enforced like Windows zone-based policy; avoid relying on it for protection.
- For state-changing commands, require
SupportsShouldProcessand use$PSCmdlet.ShouldProcess(...). - For command names, require approved verbs and Verb-Noun format.
- For quality gates, require PSScriptAnalyzer in CI and Pester tests for behaviour.
- For secret handling, prohibit plaintext credentials and recommend SecretManagement/secure providers.
- For package management guidance, prefer PSResourceGet cmdlets and only mention PowerShellGet v2 compatibility when migration context is explicit.
Enforcement Checklist
Run through this checklist for every PowerShell code answer.
Command Design
- ☐ Function uses
[CmdletBinding()](advanced function behaviour) - ☐ Name uses approved Verb-Noun pattern (verify with
Get-Verb) - ☐ State-changing commands implement
SupportsShouldProcess - ☐ Destructive actions honor
-WhatIf/-Confirm - ☐ Parameters use explicit types and validation attributes
Parameters & Pipeline
- ☐ Parameter sets are clear and unambiguous
- ☐
ValueFromPipeline/ValueFromPipelineByPropertyNameused intentionally - ☐ Switch parameters are non-mandatory unless distinguishing parameter sets
- ☐ Do not rely on implicit positional binding for readability-sensitive commands
- ☐ Use splatting for long command invocations
Output & Error Semantics
- ☐ Business output goes to success stream (objects, not formatted text)
- ☐
Write-Verbose,Write-Debug,Write-Warning,Write-Errorused correctly - ☐ Avoid
Write-Hostin reusable automation unless explicitly host-UX only - ☐ Non-terminating vs terminating error behaviour is explicit
- ☐ Stream behaviour supports automation, piping, and redirection
Tooling & Packaging
- ☐ Linting uses
Invoke-ScriptAnalyzerwith repo settings file - ☐ CI includes analyzer and test tasks
- ☐ Module/package installs use
Install-PSResourceworkflow - ☐ Module manifests are present and complete for published modules
- ☐ Cross-version compatibility checks are considered (
PSUseCompatible*rules)
Testing
- ☐ Tests use Pester v5 style (
Describe/Context/It) - ☐ File-system side effects isolated via
TestDrive:where applicable - ☐ Mocks used for external dependencies and expensive calls
- ☐ Assertions validate behaviour and error paths
- ☐ Tests are CI-runnable and deterministic
Security
- ☐ No plaintext secrets in script source
- ☐ Prefer SecretManagement/cert-based/managed identity approaches
- ☐ Avoid
Invoke-Expressionwith untrusted input - ☐ Script signing guidance is Windows-aware and practical
- ☐ Remoting guidance requires secure transport and least privilege
Anti-Patterns (instant fail)
- Unapproved verbs like
Delete-*instead of approved verb alternatives - State-changing function without
SupportsShouldProcess - Treating execution policy as the main security control
- Returning formatted strings/tables where objects are expected
- Plaintext credentials/API keys embedded in scripts
- Skipping analyzer/test quality gates for reusable automation
Quick Reference: Old → Modern
| Old / Risky | Modern / Preferred |
|---|---|
Install-Module-only guidance | Install-PSResource / PSResourceGet-first guidance |
| Simple function for reusable command | Advanced function with [CmdletBinding()] |
Delete-* / non-approved verbs | Approved Verb-Noun from Get-Verb |
| Manual confirmations only | SupportsShouldProcess + -WhatIf / -Confirm |
Write-Host for script output | Object output + stream-specific messaging |
| No lint gate | Invoke-ScriptAnalyzer with settings in CI |
| Ad-hoc script testing | Pester v5 suites with clear structure |
| Plaintext secrets in code | SecretManagement/secure credential source |
References
references/tooling.md: PSScriptAnalyzer, PSResourceGet, CI setupreferences/advanced-functions.md: CmdletBinding, ShouldProcess, parametersreferences/security.md: execution policy reality, signing, secrets, remotingreferences/testing.md: Pester v5 patterns and TestDrive usagereferences/anti-patterns.md: common pitfalls and concrete fixesreferences/web-verified-baseline.md: source-grounded claims and recency map