Cross-Platform_Function_Template.ps1
|
function Function-Name { param ( ) if ($env:OS -eq "Windows_NT") { # Windows-specific code try { # Code to execute } catch { Write-Host "An error occurred: $($_.Exception.Message)" return $null } } elseif ($env:OS -eq "Darwin") { # macOS-specific code try { # Code to execute } catch { Write-Host "An error occurred: $($_.Exception.Message)" return $null } } elseif ($env:OS -eq "Unix") { # Linux-specific code try { # Code to execute } catch { Write-Host "An error occurred: $($_.Exception.Message)" return $null } } } |