Pcornel
Automation · PowerShell Automation

Scripts

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

Back to the Topic

Answer

PowerShell scripts are .ps1 files with parameters, functions and logic. Sign them or set an execution policy like RemoteSigned, and use #Requires to declare needed modules and versions.

Remember

  • #Requires declares needed modules and versions.
  • Execution policy controls which scripts run.
  • Signing scripts proves origin.

First checks

  • Invoke-ScriptAnalyzer -Path script.ps1 — lint
  • Get-AuthenticodeSignature script.ps1 — signature
  • Get-ExecutionPolicy -List — policy

Verify in this order

script.ps1 → engine → actions

Where it usually breaks

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

Scripts · PowerShell operational reference

BoundaryScripts 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=5236

Confirmation

Confirm action

Continue?