Functions/New-IAConfiguration.ps1

Function New-IAConfiguration {
    Param(
        [Parameter(Mandatory = $true)]
        [String]$Name,
        [Parameter(Mandatory = $true)]
        $IAConfigurationDataModel,
        [Switch]$Passthru,
        [Switch]$CleanUpEmptyProperties
    )

    if($CleanUpEmptyProperties){

        $PropertyNames = $IAConfigurationDataModel | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name

        foreach($item in $PropertyNames){

            if([String]::IsNullOrEmpty($IAConfigurationDataModel."$item")){ $IAConfigurationDataModel.PSObject.Properties.Remove($item) }
        }
    }

    # This might change in the future so check here if things start breaking :D
    if($Name.EndsWith('Configuration')){ $ModuleName = $Name.Substring(0, $Name.LastIndexOf("Configuration")) }
    $ConnectorTypeId = Get-IAConnectorModuleTypes -Name $ModuleName | Select-Object -ExpandProperty ConnectorTypeId
    $ServiceUriName = Get-IAConnectorTypes -Id $ConnectorTypeId | Select-Object -ExpandProperty ServiceRoute

    $Uri = "$ServiceUriName/$($Name)s"
    $Body = $IAConfigurationDataModel | ConvertTo-Json

    Write-Verbose "Body: $Body"

    $response = Invoke-IAQuery -QueryUrl $Uri -Method Post -Body $Body

    if($PassThru){

        if ($null -eq $response) {
            return $null
        }
        return $response
    }
}