Private/Get-NSPEntraAnchorFlowStrategy.ps1

function Get-NSPEntraAnchorFlowStrategy {
    <#
    .SYNOPSIS
        Classifies one attribute flow into the source anchor. Only exact, known forms are recognized.
    .DESCRIPTION
        Returns ObjectGuid, ConsistencyGuid, ConsistencyGuidWithObjectGuidFallback, Derived (built
        from sourceAnchorBinary, so it adds nothing) or Unknown. Mentioning an attribute is not
        enough: an expression that transforms it would produce different bytes, so it is Unknown.
 
        Entra Connect's own rules wrap the fallback in a recipient-type test and a constant holding
        the anchor chosen at install. Those two forms are matched whole, never parsed: a different
        constant selects a different anchor, so any other text stays Unknown.
    #>

    [CmdletBinding()]
    [OutputType([string])]
    param([Parameter(Mandatory)]$Mapping)

    $consistency = '\[ms-?ds-consistencyguid\]'
    $objectGuid = '\[objectguid\]'
    if ([string]$Mapping.FlowType -eq 'Direct') {
        $source = @($Mapping.Source | Where-Object { $_ })
        if ($source.Count -ne 1) { return 'Unknown' }
        $text = "[$($source[0])]"
    } else {
        $text = [string]$Mapping.Expression
    }

    $flat = ($text -replace '\s', '').ToLowerInvariant()
    if ($flat -match '^converttobase64\((?<inner>.*)\)$') { $flat = $Matches.inner }
    if ($flat -eq '[sourceanchorbinary]') { return 'Derived' }
    if ($flat -match "^$objectGuid$") { return 'ObjectGuid' }
    if ($flat -match "^$consistency$") { return 'ConsistencyGuid' }
    if ($flat -match "^iif\(ispresent\($consistency\),$consistency,$objectGuid\)$") { return 'ConsistencyGuidWithObjectGuidFallback' }
    if ($flat -in (Get-NSPEntraStockAnchorFlow)) { return 'ConsistencyGuidWithObjectGuidFallback' }
    'Unknown'
}