Bird
0
0

What will be the output of this PowerShell code?

medium📝 Command Output Q13 of 15
PowerShell - String Operations
What will be the output of this PowerShell code?
$name = "Alice"
$text = @"
Hello, $name!
Welcome to PowerShell.
"@
Write-Output $text
AHello, Alice! Welcome to PowerShell.
BHello, $name! Welcome to PowerShell.
CHello, Alice! Welcome to PowerShell.
DHello, $name! Welcome to PowerShell.
Step-by-Step Solution
Solution:
  1. Step 1: Identify the here-string type

    The here-string uses @" ... "@ which is double-quoted, so variables inside are expanded.
  2. Step 2: Evaluate variable expansion

    The variable $name is replaced by its value "Alice" inside the here-string.
  3. Final Answer:

    Hello, Alice! Welcome to PowerShell. -> Option A
  4. Quick Check:

    Double-quoted here-string expands variables [OK]
Quick Trick: Double quotes expand variables inside here-strings [OK]
Common Mistakes:
  • Assuming variables are not expanded in double-quoted here-strings
  • Ignoring line breaks in output
  • Confusing single and double quotes for here-strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes