You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Guidelines for writing PowerShell scripts and modules.
applyTo
**/*.ps?(m|d)1
PowerShell Guidelines
Naming
Use descriptive names (3+ characters, no abbreviations)
Functions: PascalCase with Verb-Noun format using approved verbs
Parameters: PascalCase
Variables: camelCase
Keywords: lower-case
Classes: PascalCase
Include scope for script/global/environment variables: $script:, $global:, $env:
File naming
Class files: ###.ClassName.ps1 format (e.g. 001.SqlReason.ps1, 004.StartupParameters.ps1)
Formatting
Indentation & Spacing
Use 4 spaces (no tabs)
One space around operators: $a = 1 + 2
One space between type and variable: [String] $name
One space between keyword and parenthesis: if ($condition)
No spaces on empty lines
Try to limit lines to 120 characters
Braces
Newline before opening brace (except variable assignments)
One newline after opening brace
Two newlines after closing brace (one if followed by another brace or continuation)
Quotes
Use single quotes unless variable expansion is needed: 'text' vs "text $variable"
Arrays
Single line: @('one', 'two', 'three')
Multi-line: each element on separate line with proper indentation
Do not use the unary comma operator (,) in return statements to force
an array
Hashtables
Empty: @{}
Multi-line: each property on separate line with proper indentation
Properties: Use PascalCase
Comments
Single line: # Comment (capitalized, on own line)
Multi-line: <# Comment #> format (opening and closing brackets on own line), and indent text
No commented-out code
Comment-based help
Always add comment-based help to all functions and scripts
Comment-based help: SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, EXAMPLE sections before function/class
Comment-based help indentation: keywords 4 spaces, text 8 spaces
Include examples for all parameter sets and combinations
INPUTS: List each pipeline‑accepted type (one per line) with a 1‑line description.
OUTPUTS: List each return type (one per line) with a 1‑line description. Must match both [OutputType()] and actual returns.
.NOTES: Include only if it conveys critical info (constraints, side effects, security, version compatibility, breaking behavior). Keep to ≤2 short sentences.