Bird
0
0

What will be the output of the following PowerShell commands?

medium📝 Command Output Q13 of 15
PowerShell - System Administration
What will be the output of the following PowerShell commands?
$env:GREETING = 'Hello'
Write-Output "$env:GREETING, World!"
AHello, World!
B$env:GREETING, World!
CGREETING, World!
DError: Variable not found
Step-by-Step Solution
Solution:
  1. Step 1: Assign environment variable GREETING

    The command $env:GREETING = 'Hello' sets the environment variable GREETING to 'Hello'.
  2. 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!'.
  3. Final Answer:

    Hello, World! -> Option A
  4. Quick Check:

    Variable expands correctly = Hello, World! [OK]
Quick Trick: 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes