Challenge - 5 Problems
PowerShell Platform Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
PowerShell script output on Windows vs Linux
What is the output of this PowerShell script when run on Windows and Linux respectively?
PowerShell
Write-Output $PSVersionTable.PSPlatform
Attempts:
2 left
💡 Hint
Check the $PSVersionTable automatic variable for platform info.
✗ Incorrect
The $PSVersionTable.PSPlatform property returns 'Win32NT' on Windows and 'Unix' on Linux/macOS in PowerShell.
📝 Syntax
intermediate2:00remaining
Correct path separator in PowerShell scripts
Which option correctly sets a file path variable that works on both Windows and Linux in PowerShell?
Attempts:
2 left
💡 Hint
PowerShell accepts forward slashes as path separators on all platforms.
✗ Incorrect
Using forward slashes '/' in paths works on both Windows and Linux in PowerShell, making option B correct.
🔧 Debug
advanced2:00remaining
Identify the error in this cross-platform PowerShell script
What error will this script produce when run on Linux PowerShell?
PowerShell
if (Test-Path "C:\Windows") { Write-Output "Windows folder exists" } else { Write-Output "Folder not found" }
Attempts:
2 left
💡 Hint
Consider how Test-Path behaves with Windows paths on Linux.
✗ Incorrect
On Linux, the path 'C:\Windows' does not exist, so Test-Path returns false and the script outputs 'Folder not found'.
🚀 Application
advanced2:00remaining
Write a PowerShell snippet to detect OS and print a message
Which snippet correctly detects the OS platform and prints 'Running on Windows' or 'Running on Linux' accordingly?
Attempts:
2 left
💡 Hint
Use $PSVersionTable.PSPlatform for reliable platform detection.
✗ Incorrect
Option C uses the correct property $PSVersionTable.PSPlatform with a switch statement to detect 'Win32NT' or 'Unix'.
🧠 Conceptual
expert2:00remaining
Why is using environment variables for platform detection preferred in PowerShell scripts?
Which reason best explains why environment variables like $env:OS are less reliable than $PSVersionTable.PSPlatform for platform detection in PowerShell?
Attempts:
2 left
💡 Hint
Think about environment variables availability across platforms.
✗ Incorrect
The environment variable $env:OS is typically only set on Windows, so relying on it can cause scripts to fail or misdetect on Linux/macOS.