Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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:
✗ Incorrect
Get-ChildItem Env: lists all environment variables and their values.
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
✗ Incorrect
Use $Env:USERNAME to access the value of the USERNAME environment variable.
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
✗ Incorrect
Changes to environment variables in PowerShell last only for the current session and disappear when the window closes.
Which prefix is used to access environment variables in PowerShell?
A$Env:
B$Env.
C$Env-
D$Env_
✗ Incorrect
Environment variables are accessed with the $Env: prefix in PowerShell.
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
✗ Incorrect
Permanent environment variables must be set in system settings or the Windows registry, not just in PowerShell.
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.
Practice
(1/5)
1. What is the correct way to access the environment variable PATH in PowerShell?
The command $env:GREETING = 'Hello' sets the environment variable GREETING to 'Hello'.
Step 2: Output the string with variable expansion
The command Write-Output "$env:GREETING, World!" expands $env:GREETING to 'Hello', so the output is 'Hello, World!'.
Final Answer:
Hello, World! -> Option A
Quick Check:
Variable expands correctly = Hello, World! [OK]
Hint: Variables inside double quotes expand automatically in PowerShell [OK]
Common Mistakes:
Expecting literal $env:GREETING instead of expansion
Using single quotes which prevent expansion
Assuming environment variables are not accessible in strings
4. You run this script but get an error:
Write-Output $envMY_VAR
What is the error and how to fix it?
medium
A. Environment variables cannot be used in Write-Output
B. Variable name is case sensitive; use $env:my_var
C. Missing colon after env; fix by using $env:MY_VAR
D. Use double quotes around variable: "$envMY_VAR"
Solution
Step 1: Identify syntax error in variable name
The variable $envMY_VAR is invalid because environment variables require a colon after env, like $env:MY_VAR.
Step 2: Correct the syntax
Fix the script by changing to Write-Output $env:MY_VAR to properly access the environment variable.
Final Answer:
Missing colon after env; fix by using $env:MY_VAR -> Option C
Quick Check:
Env vars need colon after env = $env:VAR [OK]
Hint: Always use colon after env to access variables: $env:VAR [OK]
Common Mistakes:
Omitting colon after env
Assuming variable names are case sensitive
Trying to quote variable name instead of fixing syntax
5. You want to temporarily add a folder C:\Tools to the PATH environment variable for your current PowerShell session only. Which command correctly does this?
hard
A. $env:PATH = $env:PATH + ';C:\Tools'
B. setx PATH "$env:PATH;C:\Tools"
C. New-Item -Path Env:PATH -Value 'C:\Tools'
D. $env:PATH += 'C:\Tools'
Solution
Step 1: Understand session vs persistent environment variables
Modifying $env:PATH directly changes it only for the current session.
Step 2: Append new folder to existing PATH
Use $env:PATH = $env:PATH + ';C:\Tools' to add the folder, separating with a semicolon.
Final Answer:
$env:PATH = $env:PATH + ';C:\Tools' -> Option A
Quick Check:
Append with $env:PATH = $env:PATH + ';new_path' [OK]
Hint: Append with $env:PATH = $env:PATH + ';new_folder' for session only [OK]
Common Mistakes:
Using setx which changes persistent variables, not session