Use this when declaring PowerShell parameters.
Parameters · PowerShell Automation
PowerShell parameters are declared in param() with types, Mandatory, defaults and validation such as ValidateSet or ValidatePattern, so bad input fails before the script acts.
1. Parameters with types and validation ([ValidateSet], [ValidatePattern], [ValidateRange]).
2. Mandatory where required.
3. Default values safe.
4. Parameter sets for alternative usage.
5. Document with help.
caller → param block → validated values
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification path Verify boundary
Inspect parameter sets with (Get-Command <name>).ParameterSets and Get-Help <name> -Full. Test each supported parameter set, invalid values and pipeline-binding paths. For an unexpected invocation, capture InvocationInfo.BoundParameters or equivalent diagnostic context to show what the binder selected.
Step 2 Common mistakes Narrow the fault
- Parameters without validation attributes.
Step 3 Where it fails Narrow the fault
Do not confuse a syntactically accepted invocation with correct intent. Parameter-set ambiguity, implicit conversion, wildcard support and pipeline binding can all select behavior different from what the caller assumed. Separate binder decisions from command execution and target-state outcome.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Parameters have types, Mandatory and defaults.
- ValidateSet, ValidatePattern and ValidateRange reject bad input.
- Parameters can take pipeline input.
Get-Help <script> -Parameter *— parameter docs- param() with [Parameter(Mandatory)] and validation attributes — validation
- Pipeline input support — design
ReferenceWhy it matters1 section · depth on demand
In depth
PowerShell parameters provide built-in validation, mandatory prompts, pipeline input and tab completion — much more than positional arguments in other shells. Declaring them carefully makes scripts both safer and easier to use.
| Attribute | Purpose |
|---|---|
[Parameter(Mandatory)] | Required |
[ValidateSet('test','prod')] | Allowed values (and tab completion) |
[ValidatePattern('^SW-\d+$')] | Regex check |
[ValidateRange(1,64)] | Numeric range |
[ValidateScript({ Test-Path $_ })] | Custom check |
ValueFromPipeline | Accept piped objects |
[switch] | On/off flag |
| Parameter sets | Mutually exclusive groups of options |
Validation failures stop the script before it does anything, with a message naming the parameter — exactly where invalid input should be caught.
ReferenceImportant terms & boundaries1 section · depth on demand
PowerShell mechanics
PowerShell parameter binding selects a parameter set and associates supplied arguments or pipeline input with parameters using names, positions, types, validation attributes and conversion rules. Pipeline binding can occur by value and by property name. Splatting changes call syntax but still feeds the same binder, while default values and dynamic parameters can make the effective contract context dependent.
ReferenceConfiguration & state1 section · depth on demand
Authoring and lifecycle
Define parameter types and validation where they clarify the contract, use parameter sets for genuinely distinct invocation modes, and avoid ambiguous positional interfaces in automation. Treat defaults as behavior that must be versioned and tested. When forwarding parameters through wrappers, prefer deliberate splatting and remove wrapper-only keys before invoking downstream commands.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Configuration & expected output
Concrete examples are shown only when the stored reference contains an actual configuration or output shape for this Topic.
Configuration example
Assumptions: Review target identity, permissions and environment before mutation.
param([Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$Path)
Get-Item -LiteralPath $PathVerification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Microsoft Learn documentation reviewed for bounded PowerShell reference claims. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_parameters?view=powershell-7.5 · confidence 94%Quick lookup tables
Parameters · PowerShell operational reference
Topic-specific PowerShell runtime identity, persistence, verification, output and failure-boundary lookup.
| Boundary | Parameters reference |
|---|---|
| Runtime identity | PowerShell edition/version + command/module source |
| Persistent intent | Script/module/config prerequisites under source control |
| Verification | Read-only discovery → execution evidence → independent target read-back |
| Output contract | Structured objects/streams before formatting |
| Failure boundary | Separate engine/binding from transport/API/native and target-state failures |
Deep reference
Healthy vs suspicious evidence
Output interpretation
Binding errors can occur before the command body executes. Successful conversion can still alter meaning—for example string-to-enum or collection coercion—so verify resulting values inside the command when ambiguity matters. Pipeline by-property-name depends on property names and compatible types, not visual column headings.