Bird
0
0

What will be the output of this PowerShell code?

medium📝 Command Output Q5 of 15
PowerShell - String Operations
What will be the output of this PowerShell code?
$name = "Bob"
$text = @"
Hello, $name!
Welcome.
"@
Write-Output $text
AHello, $name! Welcome.
B.emocleW !boB ,olleH
CHello, Bob! Welcome.
D.emocleW !eman$ ,olleH
Step-by-Step Solution
Solution:
  1. Step 1: Understand double-quoted here-string variable expansion

    Double-quoted here-strings expand variables like $name to their values.
  2. Step 2: Analyze the output of Write-Output

    The output will replace $name with Bob and include the new lines as typed, including the final newline.
  3. Final Answer:

    Hello, Bob! Welcome. -> Option C
  4. Quick Check:

    Double-quoted here-string expands variables and preserves newlines = Hello, Bob! Welcome. [OK]
Quick Trick: Double-quoted here-strings expand variables and keep newlines [OK]
Common Mistakes:
  • Expecting variables not to expand in double-quoted here-strings
  • Ignoring the final newline in output
  • Confusing single and double-quoted here-string behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes