Src/Private/Diagram/Get-AbrADReplicationInfo.ps1

function Get-AbrADReplicationInfo {
    <#
    .SYNOPSIS
        Function to extract microsoft active directory replication information.
    .DESCRIPTION
        Build a diagram of the configuration of Microsoft Active Directory to a supported formats using Psgraph.
    .NOTES
        Version: 0.9.12
        Author: Jonathan Colon
        Twitter: @jcolonfzenpr
        Github: rebelinux
    .LINK
        https://github.com/rebelinux/Diagrammer.Microsoft.AD
    #>

    [CmdletBinding()]
    [OutputType([System.Collections.Generic.List[object]])]

    param()

    begin {
    }

    process {
        Write-Verbose -Message ($reportTranslate.NewADDiagram.buildingReplication -f $($ForestRoot))
        try {

            $ReplInfo = [System.Collections.Generic.List[object]]::new()
            $Connections = Invoke-CommandWithTimeout -Session $DiagramTempPssSession -ScriptBlock { Get-ADReplicationConnection -Filter * -Properties * }
            foreach ($Conn in $Connections) {
                $FromServer = try { ConvertTo-ADObjectName $Conn.ReplicateFromDirectoryServer.Split(',', 2)[1] -Session $DiagramTempPssSession -DC $System } catch { $Conn.ReplicateFromDirectoryServer.Split(',')[1] -replace 'CN=', '' }
                $ToServer = try { ConvertTo-ADObjectName $Conn.ReplicateToDirectoryServer -Session $DiagramTempPssSession -DC $System } catch { $Conn.ReplicateToDirectoryServer -replace 'CN=NTDS Settings,CN=', '' -replace ',.*', '' }
                $FromSite = try { $Conn.fromserver.Split(',')[3].SubString($Conn.fromserver.Split(',')[3].IndexOf('=') + 1) } catch { 'Unknown' }
                $ToSite = try { $Conn.ReplicateToDirectoryServer.Split(',')[2].SubString($Conn.ReplicateToDirectoryServer.Split(',')[2].IndexOf('=') + 1) } catch { 'Unknown' }

                $TransportProtocol = switch ([string]::IsNullOrEmpty($Conn.InterSiteTransportProtocol)) {
                    $true { 'RPC' }
                    $false { $Conn.InterSiteTransportProtocol }
                    default { 'Unknown' }
                }

                $AditionalInfo = [PSCustomObject] [ordered] @{
                    $reportTranslate.NewADDiagram.replTransportProtocol = $TransportProtocol
                    $reportTranslate.NewADDiagram.replAutoGenerated = if ($Conn.AutoGenerated) { $reportTranslate.NewADDiagram.replYes } else { $reportTranslate.NewADDiagram.replNo }
                    $reportTranslate.NewADDiagram.replEnabled = if ($Conn.enabledConnection) { $reportTranslate.NewADDiagram.replYes } else { $reportTranslate.NewADDiagram.replNo }
                }

                $TempReplInfo = [PSCustomObject]@{
                    FromServer = $FromServer
                    ToServer = $ToServer
                    FromSite = $FromSite
                    ToSite = $ToSite
                    Domain = $Domain
                    AditionalInfo = $AditionalInfo
                    TransportProtocol = $TransportProtocol
                    AutoGenerated = $Conn.AutoGenerated
                    Enabled = $Conn.enabledConnection
                }
                $ReplInfo.Add($TempReplInfo)
            }
            $ReplInfo
        } catch {
            Write-Verbose $_.Exception.Message
        }
    }
    end {}
}