Bird
0
0

Consider this PowerShell snippet:

medium📝 Command Output Q5 of 15
PowerShell - Cross-Platform PowerShell
Consider this PowerShell snippet:
if ($IsLinux) { "Linux detected" } elseif ($IsMacOS) { "Mac detected" } else { "Other OS" }
What will it output on a macOS system?
ALinux detected
BError
COther OS
DMac detected
Step-by-Step Solution
Solution:
  1. Step 1: Check $IsLinux on macOS

    $IsLinux is false on macOS, so first if block is skipped.
  2. Step 2: Check $IsMacOS on macOS

    $IsMacOS is true on macOS, so the elseif block runs.
  3. Final Answer:

    Mac detected -> Option D
  4. Quick Check:

    macOS triggers $IsMacOS true, outputs Mac detected [OK]
Quick Trick: Use elseif to check multiple platforms in order [OK]
Common Mistakes:
  • Assuming $IsLinux is true on macOS
  • Expecting else block to run on macOS
  • Thinking script throws error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes