PowerShell: Check ADFS for Duplicate Identifiers

function checkDuplicateIdf{
    write-host "Checking each relying party trust for any duplicates of identifiers..."
    $trusts=Get-AdfsRelyingPartyTrust
    $allTrustNames=$trusts.Name
    foreach ($trustName in $allTrustNames){
        write-host "Checking $trustName..." -NoNewline
        $targetTrust=Get-AdfsRelyingPartyTrust $trustName
        $targetIdentifiers=$targetTrust.Identifier
        $otherTrustNames=$allTrustNames|?{$_ -ne $trustName}
        $otherTrusts=Get-AdfsRelyingPartyTrust $otherTrustNames
        $otherIdentifiers=$otherTrusts.Identifier
        $duplicateIdentifiers=$targetIdentifiers|?{$_ -in $otherIdentifiers}
        if($duplicateIdentifiers){
            write-host "$trustName has these duplicate identifiers"
            foreach ($duplicate in $duplicateIdentifiers){
                $duplicateTrust=$otherTrusts|?{$duplicate -in $_.Identifier}
                if($duplicateTrust){
                    write-host "$duplicate in $trustName and $($duplicateTrust.Name)"
                }
            }
        }else{
            write-host " no duplicates..."
        }
    }
    # $endPoints=(Get-AdfsEndpoint).FullUrl.AbsoluteUri
    # $endPoints|?{$_.FullUrl -like 'https://john.test.com'}   
}
checkDuplicateIdf

Leave a Reply

Your email address will not be published. Required fields are marked *