Functions/Private/xRequires.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 Global:xRequires {
<#
    .SYNOPSIS
    Checks the required API Version for the current function

    .DESCRIPTION
    Checks the required API Version for the current function

    .PARAMETER Version
    The API Version that the function supports.

    The version number passed to this parameter must be in the following format.. it can't be a single character.

    - 6.2.4
    - 7.0
    - 7.0.1
    - 7.1
    - 7.2

    .INPUTS
    System.Int
    System.Management.Automation.PSObject.

    .OUTPUTS
    None

    .EXAMPLE

    function Get-Example {

        # This function does not support API versions lower than Version 7
        xRequires -Version "7.0"

    }

#>


[CmdletBinding()]

    Param (

        [Parameter(Mandatory=$true)]
        [String]$Version

    )
        # --- Test for vRA API version
        if (-not $Global:vRAConnection){

            throw "vRA Connection variable does not exist. Please run Connect-vRAServer first to create it"
        }

        # --- Convert version strings to [version] objects
        $APIVersion = [version]$Global:vRAConnection.APIVersion
        $RequiredVersion = [version]$Version

        if ($APIVersion -lt $RequiredVersion) {

            $PSCallStack = Get-PSCallStack

            throw "$($PSCallStack[1].Command) is not supported with vRA API version $($Global:vRAConnection.APIVersion)"

        }



}