internal/functions/flowcontrol/Test-Windows.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
26
27
28
#ValidationTags#Messaging,FlowControl,Pipeline,CodeStyle#
function Test-Windows {
    <#
        .SYNOPSIS
            Internal tool, used to detect non-Windows platforms
 
        .DESCRIPTION
            Some things don't work with Windows, this is an easy way to detect
 
        .EXAMPLE
            if (-not (Test-Windows)) { return }
 
            The calling function will stop if this function returns true.
    #>

    [CmdletBinding()]
    param (
        [switch]$NoWarn
    )

    if (($PSVersionTable.Keys -contains "Platform") -and $psversiontable.Platform -ne "Win32NT") {
        if (-not $NoWarn) {
            Write-Message -Level Warning -Message "This command is not supported on non-Windows platforms :("
        }
        return $false
    }

    return $true
}