Functions/Get-IAConnector.ps1

Function Get-IAConnector {
    <#
        .SYNOPSIS
            Returns a list of available Insight Analytics Connectors.
        .DESCRIPTION
            The CTGlobal Insight Analytics environment can have multiple connectors. This function is used to query the details for those connectors.
        .EXAMPLE
            Get-IAConnector
        .EXAMPLE
            Get-IAConnector -Id 'b9c8321c-7d5b-4a94-8367-e759e918d10c'
    #>

    [CmdletBinding(DefaultParameterSetName='Name')]
    Param(
        [Parameter(ParameterSetName = 'All')]
        [Switch]$All,
        [Parameter(Mandatory = $true, ParameterSetName = 'Id')]
        [Guid]$Id,
        [Parameter(Mandatory = $true, ParameterSetName = 'TenantId')]
        [Guid]$TenantId
    )
    DynamicParam
    {
        $Bucket = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameterDictionary
    
        $AttributeList = New-Object -TypeName System.Collections.ObjectModel.Collection[System.Attribute]
        $Values = (Invoke-IAQuery -QueryUrl 'Connectors' -Method Get).Value.Name
        $AttribValidateSet = New-Object System.Management.Automation.ValidateSetAttribute($Values)
        $AttributeList.Add($AttribValidateSet)
    
        $AttribParameter = New-Object System.Management.Automation.ParameterAttribute
        $AttribParameter.Mandatory = $true
        $AttribParameter.ParameterSetName = 'Name'
        $AttribParameter.Position = 0
        $AttributeList.Add($AttribParameter)
        $ParameterName = 'Name'
        $Parameter = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter($ParameterName,[String], $AttributeList)
        $Bucket.Add($ParameterName, $Parameter)
        $Bucket
    }
    End
    {
        Foreach ($key in $PSBoundParameters.Keys)
        {
            if ($MyInvocation.MyCommand.Parameters.$key.isDynamic)
            {
                Set-Variable -Name $key -Value $PSBoundParameters.$key
            }
        }
        
        $Uri = "Connectors"

        if($Id){ $Uri += "($Id)" }
        elseif($TenantId) { $Uri += "?`$filter=TenantId eq $TenantId" }
        elseif($All){}
        elseif($Name){ $Uri += "?`$filter=Name eq '$Name'" }

        $response = Invoke-IAQuery -QueryUrl $Uri -Method Get

        if($Id){ return $response }
        else{ return $response.Value }
    }
}