Public/Get-IAMCoreOrgUnitRelationship.ps1

<#
.SYNOPSIS
    Gets CoreOrgUnitRelationship objects from the IAM Core API.

.DESCRIPTION
    This function retrieves CoreOrgUnitRelationship objects from the IAM Core API.

.EXAMPLE
    Get-IAMCoreOrgUnitRelationship
#>

function Get-IAMCoreOrgUnitRelationship {
    [CmdletBinding(DefaultParameterSetName = "Default")]
    param (
        [Parameter(Mandatory = $true, ParameterSetName = "Single", ValueFromPipelineByPropertyName = $true, ValueFromPipeline = $true)]
        [ValidatePattern("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$", ErrorMessage = "Id must be a valid GUID.")] # Is a guid connector object id
        [string] $Id
    )

    process {
        $Uri = "$Script:APIRoot/sync/coreobjects/orgunits/$Id/relationships"
        Write-Verbose "Getting IAM Core org unit relationships from URI: $Uri"
        
        $Result = Invoke-RestMethod -Uri $Uri -Headers (Get-IAMCoreHeader) -SkipHttpErrorCheck -StatusCodeVariable StatusCode -Verbose:$false -ConnectionTimeoutSeconds 60 -OperationTimeoutSeconds 60

        if ($StatusCode -ne 200) {
            if ($Result.Errors) {
                throw "Failed to get relationships for org unit $($Id): $($Result.Errors -join ', ')"
            }
            else {
                throw "Failed to get relationships for org unit $($Id): Status code $StatusCode, Response: $($Result)"
            }
        }

        return $Result.Data  
    }
}