PowerShell Scripting Practices
Application skill for PoshCode PowerShellPracticeAndStyle (archived awesome-guidelines capsules). For bash glue, use shell-scripting-practices. For.NET library API naming, use dotnet-coding-practices.
Core Principle
PowerShell quality is advanced functions emitting pipeline objects with explicit, trappable errors, not Write-Host scripts with alias cmdlets.
When to Use / NOT
.ps1 controllers, .psm1 modules, advanced functions, Azure/automation scripts.
- Reviewing Verb-Noun tools, error handling, credential handling, formatting rules.
NOT when:
- Bash/sh only environments,
shell-scripting-practices.
- C#/VB syntax, language practice skills.
- Generated Pester stub files, validate generators.
Workflow
- Formatting, OTBS, blocks, splatting (
powershell-style-formatting-layout.md).
- Naming, Verb-Noun, full cmdlets, paths (
powershell-style-naming-commands.md).
- Functions/tools, process output, raw objects (
powershell-style-functions-tools.md).
- Errors/security, Stop, try/catch, PSCredential (
powershell-style-errors-security.md).
- Verify, PSScriptAnalyzer +
Invoke-Formatter on changed scripts.
Red Flags
- Missing
[CmdletBinding()]
- Mixed/inconsistent brace style
- Backtick continuation where splatting/parens work
- Alias cmdlets or positional-only calls in shared code
- Relative paths/
~ without $PSScriptRoot discipline
return in advanced function for pipeline emission
- Output from
begin/end instead of process for pipeline input
- Write-Host for data output (non-Show/Format)
- Mixed pipeline object types without separation
- Custom ping/file helpers ignoring built-in cmdlets
- Plain-text password parameters
Get-Credential inside reusable function
$continue flag error handling
$? used as error detail probe
- Null-test instead of exception on failing cmdlet
- Exported function missing comment-based help
- Trailing whitespace or semicolon terminators
- PSScriptAnalyzer findings ignored without rationale
Verification
Invoke-ScriptAnalyzer (PSScriptAnalyzer) on changed .ps1/.psm1
Invoke-Formatter / project formatter check when configured
- Pipeline test for
ValueFromPipeline functions
- Failure-path test with
-ErrorAction Stop behavior
- Capsule checklist on tool vs controller split
References
awesome-guidelines/references/powershell-style-learning-note.md
awesome-guidelines/references/powershell-style-formatting-layout.md
awesome-guidelines/references/powershell-style-naming-commands.md
awesome-guidelines/references/powershell-style-functions-tools.md
awesome-guidelines/references/powershell-style-errors-security.md
1---2name: powershell-scripting-practices3description: Use when authoring or reviewing PowerShell, PoshCode OTBS layout, Verb-Noun CmdletBinding functions, pipeline tool patterns, try/catch with -ErrorAction Stop, PSCredential security, and PSScriptAnalyzer in CI.4---56# PowerShell Scripting Practices78Application skill for PoshCode PowerShellPracticeAndStyle (archived `awesome-guidelines` capsules). For bash glue, use `shell-scripting-practices`. For.NET library API naming, use `dotnet-coding-practices`.910## Core Principle1112PowerShell quality is **advanced functions emitting pipeline objects with explicit, trappable errors**, not Write-Host scripts with alias cmdlets.1314## When to Use / NOT1516- `.ps1` controllers, `.psm1` modules, advanced functions, Azure/automation scripts.17- Reviewing Verb-Noun tools, error handling, credential handling, formatting rules.1819**NOT when:**2021- Bash/sh only environments, `shell-scripting-practices`.22- C#/VB syntax, language practice skills.23- Generated Pester stub files, validate generators.2425## Workflow26271. **Formatting**, OTBS, blocks, splatting (`powershell-style-formatting-layout.md`).282. **Naming**, Verb-Noun, full cmdlets, paths (`powershell-style-naming-commands.md`).293. **Functions/tools**, process output, raw objects (`powershell-style-functions-tools.md`).304. **Errors/security**, Stop, try/catch, PSCredential (`powershell-style-errors-security.md`).315. **Verify**, PSScriptAnalyzer + `Invoke-Formatter` on changed scripts.3233## Red Flags3435- Missing `[CmdletBinding()]`36- Mixed/inconsistent brace style37- Backtick continuation where splatting/parens work38- Alias cmdlets or positional-only calls in shared code39- Relative paths/`~` without `$PSScriptRoot` discipline40- `return` in advanced function for pipeline emission41- Output from `begin`/`end` instead of `process` for pipeline input42- Write-Host for data output (non-Show/Format)43- Mixed pipeline object types without separation44- Custom ping/file helpers ignoring built-in cmdlets45- Plain-text password parameters46- `Get-Credential` inside reusable function47- `$continue` flag error handling48- `$?` used as error detail probe49- Null-test instead of exception on failing cmdlet50- Exported function missing comment-based help51- Trailing whitespace or semicolon terminators52- PSScriptAnalyzer findings ignored without rationale5354## Verification5556- `Invoke-ScriptAnalyzer` (PSScriptAnalyzer) on changed `.ps1`/`.psm1`57- `Invoke-Formatter` / project formatter check when configured58- Pipeline test for `ValueFromPipeline` functions59- Failure-path test with `-ErrorAction Stop` behavior60- Capsule checklist on tool vs controller split616263## References6465- `awesome-guidelines/references/powershell-style-learning-note.md`66- `awesome-guidelines/references/powershell-style-formatting-layout.md`67- `awesome-guidelines/references/powershell-style-naming-commands.md`68- `awesome-guidelines/references/powershell-style-functions-tools.md`69- `awesome-guidelines/references/powershell-style-errors-security.md`