0
0
PowerShellscripting~10 mins

Environment variables in PowerShell - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to get the value of the PATH environment variable.

PowerShell
Write-Output $Env:[1]
Drag options to blanks, or click blank then click option'
AHOME
BTEMP
CUSER
DPATH
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase variable names like $Env:path which is case-sensitive.
Trying to access environment variables without $Env: prefix.
2fill in blank
medium

Complete the code to set a new environment variable named MY_VAR with value 'Hello'.

PowerShell
$Env:[1] = '[2]'
Drag options to blanks, or click blank then click option'
AMY_VAR
BHello
CTEMP
DUSER
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect variable names like PATH instead of MY_VAR.
Not using quotes around string values.
3fill in blank
hard

Fix the error in the code to correctly append a directory to the PATH environment variable.

PowerShell
$Env:PATH = $Env:PATH + ';' + [1]
Drag options to blanks, or click blank then click option'
A$NewFolder
BNewFolder
C'C:\NewFolder'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that is not defined.
Including quotes inside the concatenation causing literal quotes in PATH.
4fill in blank
hard

Fill both blanks to check if the environment variable MY_VAR exists and print its value if it does.

PowerShell
if ($Env:[1]) { Write-Output $Env:[2] } else { Write-Output 'Variable not found' }
Drag options to blanks, or click blank then click option'
AMY_VAR
BPATH
CTEMP
DUSER
Attempts:
3 left
💡 Hint
Common Mistakes
Checking one variable but printing another.
Using variable names that do not exist.
5fill in blank
hard

Fill all three blanks to create a new environment variable, check if it exists, and print a message with its value.

PowerShell
$Env:[1] = '[2]'
if ($Env:[3]) { Write-Output "Value is $Env:[3]" } else { Write-Output 'Not set' }
Drag options to blanks, or click blank then click option'
AMY_VAR
BHelloWorld
DPATH
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for setting and checking.
Forgetting to quote the string value.