Pcornel
Windows · PowerShell

Variables

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

Back to the Topic

Answer

PowerShell variables store references to values/objects and participate in scope rules. A variable can be local, script, global or otherwise scoped; automatic and preference variables expose or control engine behavior, while environment variables are surfaced through the Env: provider and affect process environment.

Remember

  • Variable name and scope are part of identity; the same name can exist in multiple scopes.
  • Assignment can replace a variable reference without changing the source object elsewhere, while mutable objects can still be shared.
  • Automatic variables are engine-provided and should not be casually repurposed.
  • Preference variables alter PowerShell behavior but are not equivalent to cmdlet parameters in every context.
  • Environment variables in a process are runtime state; persistent configuration and child-process inheritance are separate boundaries.

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

variable assigned → typed object stored in a scope → read later in that scope

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

ItemMeaningEvidence boundary
Local/script/global scopeName-resolution boundarysame name may hold different values
Automatic variableEngine-maintained statemeaning/lifecycle is variable-specific
Preference variableDefault behavior controlcmdlet explicit parameter can override behavior
Env: variableProcess environmentnot proof of persisted machine/user environment
Typed variableConversion/constraintassignment can fail or coerce

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

Confirmation

Confirm action

Continue?