-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example using the API check for how we can use Private Functions. To …
…fix issue #47
- Loading branch information
1 parent
2ae569c
commit 4968e4c
Showing
3 changed files
with
57 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
function 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 | ||
.PARAMETER Context | ||
The functions execution context. This should always be $MyInvocation | ||
.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 -Context $MyInvocation | ||
} | ||
#> | ||
|
||
[CmdletBinding()] | ||
|
||
Param ( | ||
|
||
[Parameter(Mandatory=$true)] | ||
[Int]$Version, | ||
|
||
[Parameter(Mandatory=$true)] | ||
[PSCustomobject]$Context | ||
|
||
) | ||
# --- Test for vRA API version | ||
if (-not $Global:vRAConnection){ | ||
|
||
throw "vRA Connection variable does not exist. Please run Connect-vRAServer first to create it" | ||
} | ||
|
||
elseif ($Global:vRAConnection.APIVersion -lt $Version) { | ||
|
||
throw "$($Context.MyCommand) is not supported with vRA API version $($Global:vRAConnection.APIVersion)" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters