Files
PowerShell-PowerShell/src/Microsoft.PowerShell.Linux.Host/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psm1
T
Andrew Schwartzmeyer 7673c4e90f Add Microsoft.PowerShell.Platform module
- Exports the IsCore, IsLinux, IsOSX, and IsWindows variables
- Imported by the default PSL profile
- Can be used automatically in Pester tests and Open PowerShell sessions
- Should maybe become a default module once it is polished
- PowerShellGitHubDev module does not explicitly use it because on
  FullCLR PowerShell (normal Windows development) it will not be
  imported automatically
2016-03-04 12:11:01 -08:00

19 lines
671 B
PowerShell

# Use the .NET Core APIs to determine the current platform; if a runtime
# exception is thrown, we are on FullCLR, not .NET Core.
try {
$Runtime = [System.Runtime.InteropServices.RuntimeInformation]
$OSPlatform = [System.Runtime.InteropServices.OSPlatform]
$IsCore = $true
$IsLinux = $Runtime::IsOSPlatform($OSPlatform::Linux)
$IsOSX = $Runtime::IsOSPlatform($OSPlatform::OSX)
$IsWindows = $Runtime::IsOSPlatform($OSPlatform::Windows)
} catch [System.Management.Automation.RuntimeException] {
$IsCore = $false
$IsLinux = $false
$IsOSX = $false
$IsWindows = $true
}
Export-ModuleMember -Variable IsCore, IsLinux, IsOSX, IsWindows