Public/Invoke-IBFunction.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
function Invoke-IBFunction
{
    [CmdletBinding(SupportsShouldProcess)]
    param(
        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
        [Alias('type')]
        [string]$ObjectType,
        [Parameter(Mandatory=$True)]
        [Alias('name')]
        [string]$FunctionName,
        [Alias('args')]
        [PSObject]$FunctionArgs,
        [ValidateScript({Test-NonEmptyString $_ -ThrowOnFail})]
        [Alias('host')]
        [string]$WAPIHost,
        [ValidateScript({Test-VersionString $_ -ThrowOnFail})]
        [Alias('version')]
        [string]$WAPIVersion,
        [PSCredential]$Credential,
        [switch]$SkipCertificateCheck
    )

    Begin {

        # grab the variables we'll be using for our REST calls
        $opts = Initialize-CallVars @PSBoundParameters
        $APIBase = $script:APIBaseTemplate -f $opts.WAPIHost,$opts.WAPIVersion
        $opts.Remove('WAPIHost') | Out-Null
        $opts.Remove('WAPIVersion') | Out-Null

    }

    Process {

        $uri = "$APIBase$($ObjectType)?_function=$($FunctionName)"

        if ($FunctionArgs) {
            # convert the function body to json
            $bodyJson = $FunctionArgs | ConvertTo-Json -Compress -Depth 5
            $bodyJson = [Text.Encoding]::UTF8.GetBytes($bodyJson)
            Write-Debug "JSON body:`n$($FunctionArgs | ConvertTo-Json -Depth 5)"

            # make the call
            if ($PSCmdlet.ShouldProcess($uri, "POST")) {
                Invoke-IBWAPI -Method Post -Uri $uri -Body $bodyJson @opts
            }
        }
        else {
            # make the call
            if ($PSCmdlet.ShouldProcess($uri, "POST")) {
                Invoke-IBWAPI -Method Post -Uri $uri @opts
            }
        }

    }





    <#
    .SYNOPSIS
        Call a WAPI function
 
    .DESCRIPTION
        This function allows you to call a WAPI function given a specific object reference and the function details.
 
    .PARAMETER ObjectType
        Object type string. (e.g. network, record:host, range)
 
    .PARAMETER FunctionName
        The name of the function to call.
 
    .PARAMETER FunctionArgs
        An object with the required parameters for the function.
 
    .PARAMETER WAPIHost
        The fully qualified DNS name or IP address of the Infoblox WAPI endpoint (usually the grid master). This parameter is required if not already set using Set-IBConfig.
 
    .PARAMETER WAPIVersion
        The version of the Infoblox WAPI to make calls against (e.g. '2.2').
 
    .PARAMETER Credential
        Username and password for the Infoblox appliance. This parameter is required unless it was already set using Set-IBConfig.
 
    .PARAMETER SkipCertificateCheck
        If set, SSL/TLS certificate validation will be disabled. Overrides value stored with Set-IBConfig.
 
    .EXAMPLE
        $mynetwork = @{network='10.10.12.0/24';comment='my network'}
        PS C:\>New-IBObject -ObjectType 'network' -IBObject $mynetwork
 
        Create a basic new network with a comment.
 
    .LINK
        Project: https://github.com/rmbolger/Posh-IBWAPI
 
    .LINK
        Get-IBObject
 
    #>

}