Variables
Cheat sheet · https://pcornel.dk/topic.php?topic=3042
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 versionGet-Command <name>— which cmdlet/function/exe runsGet-Help <cmdlet> -Full— syntax and parametersGet-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
| Item | Meaning | Evidence boundary |
|---|---|---|
| Local/script/global scope | Name-resolution boundary | same name may hold different values |
| Automatic variable | Engine-maintained state | meaning/lifecycle is variable-specific |
| Preference variable | Default behavior control | cmdlet explicit parameter can override behavior |
| Env: variable | Process environment | not proof of persisted machine/user environment |
| Typed variable | Conversion/constraint | assignment 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