PowerShell - Cross-Platform PowerShellWhich PowerShell expression correctly detects if the script is running on a Unix-based system?A$PSVersionTable.Platform -eq 'Unix'B$env:OS -eq 'Linux'C$PSVersionTable.Platform -eq 'Windows'D$env:OS -eq 'Unix'Check Answer
Step-by-Step SolutionSolution:Step 1: Identify platform property$PSVersionTable.Platform returns 'Unix' on Linux/macOS.Step 2: Check correct comparisonComparing to 'Unix' is the standard way to detect Unix-based OS.Final Answer:$PSVersionTable.Platform -eq 'Unix' -> Option AQuick Check:Use $PSVersionTable.Platform for OS detection [OK]Quick Trick: Check $PSVersionTable.Platform equals 'Unix' [OK]Common Mistakes:Using environment variables that differ per OSChecking for 'Linux' string directlyAssuming $env:OS exists on all platforms
Master "Cross-Platform PowerShell" in PowerShell9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PowerShell Quizzes Active Directory - New-ADUser and Set-ADUser - Quiz 15hard Active Directory - Get-ADUser - Quiz 5medium Active Directory - New-ADUser and Set-ADUser - Quiz 9hard Active Directory - Organizational unit operations - Quiz 1easy Automation Patterns - Log cleanup automation - Quiz 8hard Automation Patterns - Log cleanup automation - Quiz 4medium Cross-Platform PowerShell - PowerShell on macOS - Quiz 9hard Remote Management - PSSession management - Quiz 6medium System Administration - Service management (Get/Start/Stop-Service) - Quiz 5medium System Administration - Process management (Get/Stop-Process) - Quiz 7medium