mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
- 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
19 lines
671 B
PowerShell
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
|