Pcornel
Windows · PowerShell

Scripts

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

Back to the Topic

Answer

A PowerShell script is a .ps1 file executed by a PowerShell host. Its behavior depends on engine/version, invocation method, parameters, current environment, modules, execution policy/signature rules, working directory and external dependencies.

Remember

  • Normal script invocation runs in a script scope; dot-sourcing deliberately executes in the caller scope.
  • Execution policy can affect script loading on Windows but is not a security boundary.
  • Script success depends on engine/module/dependency context, not file content alone.
  • PowerShell terminating errors, non-terminating errors and native process exit codes require explicit handling.
  • Reproducible scripts should make inputs, prerequisites, target scope and verification explicit.

First checks

  • $PSVersionTable — PowerShell edition and version
  • Get-Command <name> — which cmdlet/function/exe runs
  • Get-Help <cmdlet> -Full — syntax and parameters
  • Get-ExecutionPolicy -List — execution policy per scope

Verify in this order

script file → execution policy check → parsed → runs in its scope → exit code

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 → Scripts reference map

ItemMeaningEvidence boundary
.ps1 fileScript sourcefile presence does not prove execution context
Parameter blockDeclared inputsvalidation does not prove external prerequisites
Script scopeNormal isolation boundarydot-sourcing changes caller scope
Exit/errorExecution outcome signalmust account for non-terminating/native failures
VerificationTarget-state checkstronger than script completion alone

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

Confirmation

Confirm action

Continue?