Public/Get-IBConfig.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
function Get-IBConfig
{
    [CmdletBinding(DefaultParameterSetName='Specific')]
    [OutputType('PoshIBWAPI.IBConfig')]
    param(
        [Parameter(ParameterSetName='Specific',Position=0)]
        [ValidateScript({Test-NonEmptyString $_ -ThrowOnFail})]
        [string]$ProfileName,
        [Parameter(ParameterSetName='List',Mandatory)]
        [switch]$List
    )

    if ('Specific' -eq $PSCmdlet.ParameterSetName) {

        if (-not $ProfileName) {

            # return the current profile
            $profName = Get-CurrentProfile
            $p = [PSCustomObject]$script:Profiles.$profName |
                Select-Object @{L='ProfileName';E={$profName}},WAPIHost,WAPIVersion,Credential,SkipCertificateCheck
            $p.PSObject.TypeNames.Insert(0,'PoshIBWAPI.IBConfig')
            return $p

        } else {

            # return the selected profile if it exists
            if ($ProfileName -in $script:Profiles.Keys) {
                $p = [PSCustomObject]$script:Profiles.$ProfileName |
                    Select-Object @{L='ProfileName';E={$ProfileName}},WAPIHost,WAPIVersion,Credential,SkipCertificateCheck
                $p.PSObject.TypeNames.Insert(0,'PoshIBWAPI.IBConfig')
                return $p
            } else {
                return $null
            }

        }

    } else {

        # list all configs
        foreach ($profName in ($script:Profiles.Keys | Sort-Object)) {
            $p = [PSCustomObject]$script:Profiles.$profName |
                Select-Object @{L='ProfileName';E={$profName}},WAPIHost,WAPIVersion,Credential,SkipCertificateCheck
            $p.PSObject.TypeNames.Insert(0,'PoshIBWAPI.IBConfig')
            Write-Output $p

        }

    }




    <#
    .SYNOPSIS
        Get one or more connection profiles.
 
    .DESCRIPTION
        When calling this function with no parameters, the currently active profile will be returned. These values will be used by related function calls to the Infoblox API unless they are overridden by the function's own parameters.
 
        When called with -ProfileName, the profile matching that name will be returned. When called with -List, all profiles will be returned.
 
    .PARAMETER ProfileName
        The name of the connection profile to return.
 
    .PARAMETER List
        If set, list all connection profiles currently stored.
 
    .EXAMPLE
        Get-IBConfig
 
        Get the current connection profile.
 
    .EXAMPLE
        Get-IBConfig -List
 
        Get all connection profiles.
 
    .LINK
        Project: https://github.com/rmbolger/Posh-IBWAPI
 
    .LINK
        Set-IBConfig
 
    .LINK
        Get-IBObject
 
    #>

}