Functions
Cheat sheet · https://pcornel.dk/topic.php?topic=3045
Answer
PowerShell functions package reusable logic. Advanced functions use CmdletBinding-style metadata so they can behave more like cmdlets with parameter binding, common parameters, pipeline support and optionally ShouldProcess.
Remember
- Anything written to the success output stream can become function output, including accidental expressions.
- Advanced functions can expose common parameters and cmdlet-like parameter metadata.
- Pipeline-aware functions should distinguish Begin/Process/End behavior and cardinality.
- Function-local scope protects variables unless broader scopes are explicitly targeted.
SupportsShouldProcessenables a control contract but still requires the function to call ShouldProcess around state-changing actions.
First checks
$PSVersionTable— PowerShell edition and versionGet-Command <name>— which cmdlet/function/exe runsGet-Help <cmdlet> -Full— syntax and parametersGet-ExecutionPolicy -List— execution policy per scope
Verify in this order
function defined → parameters bound → logic runs → objects returned
Where it usually breaks
First mismatch in definition/configuration → security context → service/task/process creation → runtime state → output/side effect → event/performance evidence; preserve identity/native error/pre-state before mutation.
PowerShell → Functions reference map
| Item | Meaning | Evidence boundary |
|---|---|---|
| Parameters | Input contract | binding success does not prove valid external state |
| Begin | Once-before pipeline | not per-item processing |
| Process | Per pipeline item | cardinality/error behavior must be defined |
| End | Finalization | can run after many partial results |
| Output stream | Caller data contract | accidental output can break consumers |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=3045