Private/Get-Platform.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Function Get-Platform {
    [cmdletbinding()]
    Param()

    # the IsWindows/IsMacOs/IsLinux variables are not present in powershell 5 and lower
    if ( -not (Test-Path 'variable:/IsWindows') ) {
        $script:IsWindows = $true
        $script:IsLinux = $false
        $script:IsMacOS = $false
    }

    # powershell 6+
    if ($IsWindows) {
        $Platform = "windows"
    }
    if ($IsMacOS) {
        $Platform = "darwin"
    }
    if ($IsLinux) {
        $Platform = "linux"
    }

    Return $Platform

}