Pcornel
Automation · PowerShell Automation

Functions

Cheat sheet · https://pcornel.dk/topic.php?topic=5234

Back to the Topic

Answer

PowerShell functions group reusable code with a name and param() block. Return objects rather than formatted text so the output can be piped and filtered.

Remember

  • Functions use a param() block.
  • Return objects, not formatted text.
  • Keep functions small and focused.

First checks

  • Get-Command -CommandType Function — defined functions
  • Get-Help <function> — comment-based help
  • Invoke-Pester — tests

Verify in this order

input → function → objects

Where it usually breaks

Script/input → command/module binding → local/remoting session → request accepted → command result → target object read-back → effective runtime state → workload.

Functions · PowerShell operational reference

BoundaryFunctions reference
Runtime identityPowerShell edition/version + command/module source
Persistent intentScript/module/config prerequisites under source control
VerificationRead-only discovery → execution evidence → independent target read-back
Output contractStructured objects/streams before formatting
Failure boundarySeparate engine/binding from transport/API/native and target-state failures

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5234

Confirmation

Confirm action

Continue?