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?
$count = 5
$message = "You have $count new messages."
Write-Output $message
AYou have 5 new messages.
BYou have $count new messages.
CYou have new messages.
DSyntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable interpolation in the string

    The variable $count has value 5, and inside double quotes it will be replaced by 5.
  2. Step 2: Output the interpolated string

    The string becomes "You have 5 new messages.", so Write-Output prints that exact text.
  3. Final Answer:

    You have 5 new messages. -> Option A
  4. Quick Check:

    Variable replaced inside double quotes = You have 5 new messages. [OK]
Quick Trick: Variables inside double quotes show their values [OK]
Common Mistakes:
  • Expecting variable name to print literally
  • Confusing single quotes with double quotes
  • Thinking it causes an error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes