Private/Test-PSCore.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
Function Test-PSCore {
    <#
        .SYNOPSIS
            Returns True is running on PowerShell Core.

        .NOTES
            Author: Aaron Parker
            Twitter: @stealthpuppy

        .PARAMETER Version
            The version of PowerShell Core. Optionally specified where value needs to be something other than 6.0.0.
    #>

    [CmdletBinding()]
    [OutputType([Boolean])]
    Param (
        [Parameter(ValueFromPipeline)]
        [String] $Version = '6.0.0'
    )

    # Check whether current PowerShell environment matches or is higher than $Version
    If (($PSVersionTable.PSVersion -ge [version]::Parse($Version)) -and ($PSVersionTable.PSEdition -eq "Core")) {
        Write-Output $True
    }
    Else {
        Write-Output $False
    }
}