0
0
PowerShellscripting~5 mins

Environment variables in PowerShell - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an environment variable in PowerShell?
An environment variable is a named value stored by the operating system that programs can use to get information like paths or settings. In PowerShell, you can access them to customize scripts or system behavior.
Click to reveal answer
beginner
How do you list all environment variables in PowerShell?
Use the command Get-ChildItem Env: or its alias gci Env: to see all environment variables and their values.
Click to reveal answer
beginner
How can you read the value of an environment variable named 'PATH' in PowerShell?
Use $Env:PATH to get the value of the PATH environment variable.
Click to reveal answer
beginner
How do you set or change an environment variable in PowerShell for the current session?
Assign a new value like $Env:MYVAR = 'Hello'. This change lasts only while the PowerShell window is open.
Click to reveal answer
beginner
What happens if you set an environment variable in PowerShell and then close the window?
The environment variable change is lost because it was only set for the current session. To keep it permanently, you must set it in system settings or the registry.
Click to reveal answer
Which PowerShell command lists all environment variables?
AGet-Process
BGet-ChildItem Env:
CGet-Content Env:
DSet-Variable Env:
How do you access the value of the environment variable 'USERNAME' in PowerShell?
A$Env:USERNAME
B$Env.USERNAME
CGet-Env USERNAME
DRead-Env USERNAME
If you set $Env:MYVAR = 'Test' in PowerShell, when does this change disappear?
ANever, it is permanent
BImmediately after setting
CWhen you close the PowerShell window
DAfter restarting the computer
Which prefix is used to access environment variables in PowerShell?
A$Env:
B$Env.
C$Env-
D$Env_
To permanently set an environment variable in Windows, you should:
ARun Get-ChildItem Env:
BUse $Env:VAR = 'value' in PowerShell
CRestart PowerShell
DSet it in system settings or registry
Explain how to view, read, and set environment variables in PowerShell.
Think about commands to list, read, and assign environment variables.
You got /4 concepts.
    Describe the difference between temporary and permanent environment variables in Windows and PowerShell.
    Consider where variables are stored and how long they last.
    You got /4 concepts.