Bird
0
0

What is the output of this PowerShell code?

medium📝 Command Output Q13 of 15
PowerShell - Regular Expressions
What is the output of this PowerShell code?
$text = "PowerShell is fun"
if ($text -match "fun") { "Yes" } else { "No" }
ANo
BTrue
CYes
DFalse
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the match condition

    The string "$text" contains the word "fun" so $text -match "fun" returns True.
  2. Step 2: Determine the if statement output

    Since the condition is True, the if block returns "Yes".
  3. Final Answer:

    Yes -> Option C
  4. Quick Check:

    Pattern found, output is "Yes" [OK]
Quick Trick: If pattern found, -match returns True [OK]
Common Mistakes:
  • Confusing output with Boolean True/False
  • Assuming output is the matched string
  • Ignoring the if-else structure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes