Private/Compare-MinimumVersion.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
Function Compare-MinimumVersion {
    <#
    .SYNOPSIS
    Compares 2 version numbers

    .DESCRIPTION
    Compares 2 System.Version numbers.
    Returns True if Version is greater than or equal to MinimumVersion

    .PARAMETER Version
    A Version to compare against a Minimum Version

    .PARAMETER MinimumVersion
    The Minimum Version to compare against

    .EXAMPLE
    Compare-MinimumVersion -Version "9.8.0" -MinimumVersion "8.9.0"

    Returns True

    .EXAMPLE
    Compare-MinimumVersion -Version "9.8.0" -MinimumVersion "9.9.0"

    Returns False

    .NOTES

    #>

    [CmdletBinding()]
    [OutputType('System.Boolean')]
    Param(
        # A Version to compare against a Minimum Version
        [Parameter(
            Mandatory = $true,
            ValueFromPipelineByPropertyName = $true
        )]
        [Alias("ExternalVersion")]
        [System.Version]
        $Version,

        # The Minimum Version to compare against
        [Parameter(
            Mandatory = $true,
            ValueFromPipelineByPropertyName = $true
        )]
        [System.Version]
        $MinimumVersion
    )

    Begin {}

    Process {

        # Only compare if version greater than "0.0"
        If($Version -gt "0.0") {

            #Determine if Version is greater than or equal to MinimumVersion
            If($Version -ge $MinimumVersion) {

                Write-Verbose "Version Requirement Met"
                #Version is greater than or equal to MinimumVersion
                $True

            } Else {

                Write-Verbose "Version Requirement Not Met"
                #Version is less than MinimumVersion
                $False

            }

        }

        #Version is 0.0
        Else {

            #Skip - Return True
            Write-Verbose "Version Requirement Not Checked"
            $True

        }

    }

    End {}

}