Bird
0
0

You want to write a PowerShell script that lists files differently on Windows and Linux but works on both. Which approach best extends your script's reach?

hard📝 Application Q15 of 15
PowerShell - Cross-Platform PowerShell
You want to write a PowerShell script that lists files differently on Windows and Linux but works on both. Which approach best extends your script's reach?
AUse $PSVersionTable.Platform to detect OS and run platform-specific commands
BUse Windows-only cmdlets and expect errors on Linux
CWrite separate scripts for each OS and run manually
DIgnore OS differences and run same commands everywhere
Step-by-Step Solution
Solution:
  1. Step 1: Identify cross-platform detection method

    Using $PSVersionTable.Platform lets the script detect OS at runtime.
  2. Step 2: Apply platform-specific commands conditionally

    Run Windows commands if on Windows, Linux commands if on Unix, ensuring script works everywhere.
  3. Final Answer:

    Use $PSVersionTable.Platform to detect OS and run platform-specific commands -> Option A
  4. Quick Check:

    Detect OS, run matching commands = best cross-platform practice [OK]
Quick Trick: Detect OS, then run matching commands for best reach [OK]
Common Mistakes:
  • Using Windows-only commands without checks
  • Writing separate scripts instead of one cross-platform script
  • Ignoring OS differences causing failures

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes