Bird
0
0

Identify the error in this PowerShell code snippet:

medium📝 Debug Q14 of 15
PowerShell - Variables and Data Types
Identify the error in this PowerShell code snippet:
$user = 'Bob'
$message = 'Welcome, $user!'
Write-Output $message
AVariable $user is not defined
BSingle quotes prevent variable interpolation
CMissing semicolon after assignment
DWrite-Output cannot print variables
Step-by-Step Solution
Solution:
  1. Step 1: Check variable definition

    $user is defined correctly with single quotes, so no error there.
  2. Step 2: Analyze string interpolation

    The $message string uses single quotes, so $user is not replaced by its value but printed literally.
  3. Final Answer:

    Single quotes prevent variable interpolation -> Option B
  4. Quick Check:

    Single quotes block interpolation = B [OK]
Quick Trick: Use double quotes to enable variable replacement [OK]
Common Mistakes:
  • Thinking single quotes allow interpolation
  • Expecting semicolons in PowerShell
  • Assuming Write-Output can't print variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes