Private/Assert-VersionRequirement.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
Function Assert-VersionRequirement {
    <#
.SYNOPSIS
Affirms that a version satisfies a required level

.DESCRIPTION
Throws an error if a provided version number odes not meet or exceed a required level.

.PARAMETER ExternalVersion
A version number to comapre against the required version

.PARAMETER RequiredVersion
The version number the ExternalVersion Number must meet.v

.EXAMPLE
Assert-VersionRequirement -ExternalVersion 1.0 -RequiredVersion 2.0

Throws an error as 1.0 does not equal or exceed 2.0

.EXAMPLE
Assert-VersionRequirement -ExternalVersion 1.0 -RequiredVersion 0.5

Returns nothing as 1.0 exceeds 0.5

.NOTES
General notes
#>

    [CmdletBinding()]
    Param(
        # The Current Software Version
        [Parameter(
            Mandatory = $true,
            ValueFromPipelineByPropertyName = $true
        )]
        [System.Version]
        $ExternalVersion,

        # The Required Software Version
        [Parameter(
            Mandatory = $true,
            ValueFromPipelineByPropertyName = $true
        )]
        [System.Version]
        $RequiredVersion
    )

    Begin {

        $ParentFunction = $((Get-ParentFunction).FunctionName)
        $UsedParameterSet = $((Get-ParentFunction).ParameterSetName)

    }

    Process {

        If(-not (Compare-MinimumVersion -Version $ExternalVersion -MinimumVersion $RequiredVersion)) {

            Throw "CyberArk $ExternalVersion does not meet the minimum version requirement of $RequiredVersion for $ParentFunction (using ParameterSet: $UsedParameterSet)"

        }

    }

    End {}

}