Complete the code to get the value of the PATH environment variable.
Write-Output $Env:[1]The $Env:PATH variable holds the system PATH environment variable.
Complete the code to set a new environment variable named MY_VAR with value 'Hello'.
$Env:[1] = '[2]'
To create or update an environment variable, assign a value to $Env:VariableName. Here, MY_VAR is the variable name and 'Hello' is the value.
Fix the error in the code to correctly append a directory to the PATH environment variable.
$Env:PATH = $Env:PATH + ';' + [1]
To append a directory path, use the full path string with quotes inside the concatenation. The path must be a string like 'C:\NewFolder'.
Fill both blanks to check if the environment variable MY_VAR exists and print its value if it does.
if ($Env:[1]) { Write-Output $Env:[2] } else { Write-Output 'Variable not found' }
Checking $Env:MY_VAR tests if the variable exists. Printing the same variable outputs its value.
Fill all three blanks to create a new environment variable, check if it exists, and print a message with its value.
$Env:[1] = '[2]' if ($Env:[3]) { Write-Output "Value is $Env:[3]" } else { Write-Output 'Not set' }
First, set $Env:MY_VAR to 'HelloWorld'. Then check if $Env:MY_VAR exists and print its value.