Pcornel
Automation · PowerShell Automation

Variables

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

Back to the Topic

Answer

PowerShell variables start with $, hold any object type and can be strongly typed with [int] or [string]. Scope modifiers like $script: and $global: control visibility.

Remember

  • Variables start with $ and can be typed.
  • Scopes include local, script and global.
  • $using: passes values to remote or parallel blocks.

First checks

  • Get-Variable — variables in scope
  • Set-StrictMode -Version Latest — catch undefined variables
  • $env:PATH — environment variables

Verify in this order

value → $variable → scope

Where it usually breaks

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

Variables · PowerShell operational reference

BoundaryVariables 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=5233

Confirmation

Confirm action

Continue?