Environment Variables
Cheat sheet · https://pcornel.dk/topic.php?topic=2933
Answer
Environment variables are name/value pairs exposed through a process environment block. Windows commonly distinguishes Process, User and Machine scopes. A new process normally inherits a copy of its parent’s environment, while persistent User/Machine values seed future process environments.
Remember
- A process owns its current environment block. Changing a persistent variable does not rewrite every existing process.
- User and Machine variables persist; Process-scope changes disappear with that process unless explicitly persisted elsewhere.
- Child processes normally inherit a copy of the parent environment at creation time.
%NAME%is common cmd expansion; PowerShell uses$env:NAMEfor process-environment access.- Machine/User persistent environment settings are backed by Registry locations, but applications consume process state.
First checks
Get-ChildItem Env:— environment of the current process[Environment]::GetEnvironmentVariable('<Name>','Machine')— machine-level value[Environment]::GetEnvironmentVariable('<Name>','User')— user-level valuesetx <Name> <Value>— persist for the user (new processes)
Verify in this order
machine and user variables → merged at logon/process start → inherited by child processes → read by the program
Where it usually breaks
First mismatch in target identity/version → persistent configuration/source of truth → provider/service/control plane → runtime/effective state → user/workload-visible result → event/log evidence; preserve identity/native error/pre-state before mutation.
Environment-variable scopes
| Scope | Lifetime / persistence | Typical verification |
|---|---|---|
| Process | current process lifetime | read from the exact shell/process |
| User | persistent for one user; seeds future processes | compare User config with a newly started process |
| Machine | persistent system-wide; seeds future processes | compare Machine config with newly started user/service processes |
| Child process | inherits a copy from parent unless overridden | identify parent and creation time |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2933