Public/Build-ConnectorOperation.ps1

<#
.SYNOPSIS
    Builds a connector operation to be executed against the Connector Data API.

.DESCRIPTION
    Creates a hashtable representing a Create, Update, or Delete operation for a connector object.
    Update and Delete operations require an Id referencing the existing object in the API.
    The resulting operation can be passed to Complete-ConnectorSyncSessionOperation.

.PARAMETER OperationType
    The type of operation to perform. Must be one of: Create, Update, Delete.

.PARAMETER Id
    The API-assigned identifier of the existing connector object. Required for Update and Delete operations.

.PARAMETER ConnectorObject
    The connector object hashtable (as produced by Build-ConnectorObject) to operate on.

.OUTPUTS
    System.Collections.Hashtable

.EXAMPLE
    $obj = Build-ConnectorObject -ExternalId "user-123" -ObjectType "User" -Data @{ DisplayName = "Jane Doe" }
    $op = Build-ConnectorOperation -OperationType Create -ConnectorObject $obj

.EXAMPLE
    $op = Build-ConnectorOperation -OperationType Update -Id "api-id-456" -ConnectorObject $obj
#>

function Build-ConnectorOperation {
    [CmdletBinding()]
    [OutputType([System.Collections.Hashtable])]
    param (
        [Parameter(Mandatory = $true)]
        [ValidateSet("Create", "Update", "Delete")]
        [string] $OperationType,
        
        [Parameter(Mandatory = $false)]
        [string] $Id,

        [Parameter(Mandatory = $true)]
        [System.Collections.Hashtable] $ConnectorObject
    ) 
    
    process {
        if($OperationType -in "Update", "Delete") {
            if([string]::IsNullOrEmpty($Id)) {
                throw "Operation $OperationType requires an Id"
            }
        }
        @{
            Id              = [string]::IsNullOrEmpty($Id) ? $null : $Id
            OperationType   = $OperationType
            ConnectorObject = $ConnectorObject
        }
    }
}