Platform-specific considerations
📖 Scenario: You are writing a PowerShell script that needs to behave differently depending on the operating system it runs on. This is common when scripts must work on Windows, Linux, or macOS.
🎯 Goal: Build a PowerShell script that detects the platform it is running on and stores the platform name in a variable. Then, use this information to create a message that tells the user which platform the script detected.
📋 What You'll Learn
Create a variable called
platform that stores the current operating system name.Create a variable called
message that uses platform to build a message string.Use a
switch statement to set platform based on the OS.Print the
message to the console.💡 Why This Matters
🌍 Real World
Scripts often need to behave differently on Windows, Linux, or macOS. Detecting the platform helps automate tasks correctly.
💼 Career
Knowing how to write cross-platform scripts is valuable for system administrators and automation engineers who manage diverse environments.
Progress0 / 4 steps