Public/New-IAMCoreSyncRule.ps1

function New-IAMCoreSyncRule {
    [CmdletBinding(SupportsShouldProcess = $true)]
    param (
        [Parameter(Mandatory = $true)]
        [string]$Name,

        [Parameter(Mandatory = $false)]
        [string]$Description,

        [Parameter(Mandatory = $false)]
        [string]$JoinScope = "default",

        [Parameter(Mandatory = $true)]
        [string]$ConnectorId,

        [Parameter(Mandatory = $true)]
        [boolean]$ProvisioningEnabled,

        [Parameter(Mandatory = $false)]
        [boolean]$DisableProvideCoreObjectExistence = $false,

        [Parameter(Mandatory = $true)]
        [ValidateSet("Identity", "Relationship", "OrgUnit")]
        [string]$CoreObjectType,

        [Parameter(Mandatory = $true)]
        [string]$ConnectorObjectType,

        [Parameter(Mandatory = $false)]
        [System.Collections.Hashtable[]] $Scope = @(
            @{
                '$type' = "true"
            }
        ),

        [Parameter(Mandatory = $false)]
        [System.Collections.Hashtable[]] $InboundAttributeFlows = @(),

        [Parameter(Mandatory = $false)]
        [int] $Priority = (Get-Random -Minimum 100 -Maximum 1000)
    )

    if ($PSCmdlet.ShouldProcess("Creating IAM Core sync rule '$Name'")) {
        $Body = @{
            name                              = $Name
            description                       = $Description
            connectorId                       = $ConnectorId
            provisioningEnabled               = $ProvisioningEnabled
            disableProvideCoreObjectExistence = $DisableProvideCoreObjectExistence
            coreObjectType                    = $CoreObjectType
            connectorObjectType               = $ConnectorObjectType
            scope                             = $Scope
            joinScope                         = $JoinScope
            inboundAttributeFlows             = $InboundAttributeFlows
            priority                          = $Priority
        } | ConvertTo-Json -Depth 100

        $Result = Invoke-RestMethod -Uri "$Script:APIRoot/sync/syncrules" -Headers (Get-IAMCoreHeader) -Method Post -Body $Body -ContentType "application/json" -SkipHttpErrorCheck -StatusCodeVariable "statuscode"

        if ($Result.IsSuccess) {
            return $Result.Data
        }
        else {
            throw "Failed to create IAM Core sync rule (Status code $statuscode): $($Result)"
        }
    
        
    }
}