Introduction
Cross-platform means your script works on many types of computers. This helps more people use your work easily.
Jump into concepts and practice - no test required
Cross-platform means your script works on many types of computers. This helps more people use your work easily.
# No special syntax, but use commands available on all platforms # Example: Use 'Write-Output' instead of Windows-only commands
Use commands and features supported on all target platforms.
Test your script on each platform to ensure it works well.
Write-Output "Hello, world!"$date = Get-Date
Write-Output "Today is $date"This simple script shows a message that works on all platforms with PowerShell.
Write-Output "This script runs on Windows, Linux, and macOS with PowerShell."PowerShell Core (7+) is cross-platform, unlike Windows PowerShell.
Avoid Windows-only commands like 'Get-WmiObject' for cross-platform scripts.
Use environment variables carefully, as names may differ across systems.
Cross-platform scripts reach more users by working on many systems.
Use common commands and test on each platform.
PowerShell Core is designed for cross-platform scripting.
if ($PSVersionTable.Platform -eq 'Unix') { 'Cross-platform script running' } else { 'Windows script running' }if ($env:OS -eq 'Windows_NT') { Write-Host 'Windows' } else { Write-Host 'Linux or macOS' }