Challenge - 5 Problems
Environment Variable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this PowerShell command?
Consider the following command executed in PowerShell. What will it output?
PowerShell
Write-Output $env:USERNAME
Attempts:
2 left
💡 Hint
Environment variables in PowerShell are accessed with $env: prefix.
✗ Incorrect
The $env:USERNAME variable contains the current user's username. Write-Output prints its value.
📝 Syntax
intermediate2:00remaining
Which command correctly sets a new environment variable in PowerShell for the current session?
You want to set an environment variable named 'MY_VAR' with value 'HelloWorld' for the current PowerShell session. Which command is correct?
Attempts:
2 left
💡 Hint
PowerShell uses $env: prefix to set environment variables.
✗ Incorrect
In PowerShell, environment variables are set by assigning a value to $env:VariableName.
🔧 Debug
advanced2:00remaining
Why does this script fail to update the environment variable permanently?
This script tries to set an environment variable permanently but it doesn't work as expected. Why?
$env:PATH = "$env:PATH;C:\NewFolder"
PowerShell
$env:PATH = "$env:PATH;C:\NewFolder"Attempts:
2 left
💡 Hint
Think about session scope vs permanent environment variables.
✗ Incorrect
Assigning to $env:PATH changes the variable only for the current PowerShell session. To change it permanently, you must modify the registry or use system settings.
🚀 Application
advanced2:00remaining
How to retrieve and display all environment variables in PowerShell?
You want to list all environment variables and their values in PowerShell. Which command will do this?
Attempts:
2 left
💡 Hint
Environment variables are stored in a special drive in PowerShell.
✗ Incorrect
Get-ChildItem Env: lists all environment variables and their values because Env: is a PS drive for environment variables.
🧠 Conceptual
expert2:00remaining
What happens when you run this PowerShell command?
What is the output or effect of running this command?
[Environment]::SetEnvironmentVariable('TEST_VAR', '123', 'User')
Write-Output $env:TEST_VAR
PowerShell
[Environment]::SetEnvironmentVariable('TEST_VAR', '123', 'User') Write-Output $env:TEST_VAR
Attempts:
2 left
💡 Hint
Think about session environment variables vs permanent environment variables.
✗ Incorrect
SetEnvironmentVariable with 'User' scope sets the variable permanently but does not update the current session's environment variables. So $env:TEST_VAR remains unchanged until a new session starts.