Bird
0
0

What will be the output of this PowerShell script when run on macOS?

medium📝 Command Output Q13 of 15
PowerShell - Cross-Platform PowerShell
What will be the output of this PowerShell script when run on macOS?
if ($IsWindows) { Write-Output 'Windows' } elseif ($IsLinux) { Write-Output 'Linux' } elseif ($IsMacOS) { Write-Output 'MacOS' } else { Write-Output 'Unknown' }
AMacOS
BLinux
CWindows
DUnknown
Step-by-Step Solution
Solution:
  1. Step 1: Understand the platform variables

    On macOS, $IsMacOS is true, while $IsWindows and $IsLinux are false.
  2. Step 2: Follow the conditional logic

    The script checks $IsWindows (false), then $IsLinux (false), then $IsMacOS (true), so it outputs 'MacOS'.
  3. Final Answer:

    MacOS -> Option A
  4. Quick Check:

    macOS detection outputs 'MacOS' [OK]
Quick Trick: Check $IsMacOS true for Mac output in if-elseif chain [OK]
Common Mistakes:
  • Assuming Linux output on macOS
  • Ignoring else block
  • Confusing $IsWindows with $IsMacOS

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes