Bird
0
0

Which PowerShell command syntax is correct for checking the OS platform in a cross-platform script?

easy📝 Syntax Q12 of 15
PowerShell - Cross-Platform PowerShell
Which PowerShell command syntax is correct for checking the OS platform in a cross-platform script?
Aif ($env:OS -eq 'Linux') { Write-Host 'Linux' }
Bif ($PSVersionTable.OS -eq 'Windows') { Write-Host 'Windows' }
Cif ($PSVersionTable.Platform -eq 'Unix') { Write-Host 'Linux or macOS' }
Dif ($Platform -eq 'Unix') { Write-Host 'Unix' }
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct property for OS platform

    $PSVersionTable.Platform is the standard way to check OS platform in PowerShell Core.
  2. Step 2: Check syntax correctness

    if ($PSVersionTable.Platform -eq 'Unix') { Write-Host 'Linux or macOS' } uses correct syntax and property. Others use invalid or non-existent properties.
  3. Final Answer:

    if ($PSVersionTable.Platform -eq 'Unix') { Write-Host 'Linux or macOS' } -> Option C
  4. Quick Check:

    Use $PSVersionTable.Platform for OS check [OK]
Quick Trick: Use $PSVersionTable.Platform to detect OS [OK]
Common Mistakes:
  • Using $env:OS which is Windows-only
  • Referencing non-existent $PSVersionTable.OS
  • Using undefined variable $Platform

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes