How to check DFSR or FRS for Sysvol Replication with Powershell

active-directoryreplicationsysvol

I've been investigating how to check whether DFSR or FRS for Sysvol Replication is used with powershell. Here is my naive methods, I have tried to implement.

  1. Check if the DFS replication is installed

PS C:> Get-WindowsFeature|where Displayname -Match "Replication"

Display Name                                            Name                       Install State
------------                                            ----                       -------------
        [ ] DFS Replication                             FS-DFS-Replication             Available

So, this proves that it's using FRS over DFSR??

  1. Check DN

    $FRSsysvol = "CN=Domain System Volume (SYSVOL share),CN=File Replication Service,CN=System,"+(Get-ADDomain $domain).DistinguishedName
    $DFSRsysvol = "CN=Domain System Volume,CN=DFSR-GlobalSettings,CN=System,"+(Get-ADDomain $domain).DistinguishedName
    
    $frs = Get-ADObject -Filter { distinguishedName -eq $FRSsysvol }
    $dfsr = Get-ADObject -Filter { distinguishedName -eq $DFSRsysvol } 
    
    
    if ( $frs -ne $null ) { Write-Host -ForegroundColor red "FRS" }
    
    elseif ( $dfsr -ne $null ) { Write-Host -ForegroundColor green "DFS-R" }
    
    else { Write-Host -ForegroundColor Red "unknown" }
    

This returns "FRS". But when I double check $frs and $dfsr output. Both are not $null. Both return DN, Name, ObjectClass and ObjectGUID as well. So, What's problem here?

Best Answer

I have found the way how to implement this, hope this help!

        $currentDomain =(Get-ADDomainController).hostname

        $defaultNamingContext = (([ADSI]"LDAP://$currentDomain/rootDSE").defaultNamingContext)
        $searcher = New-Object DirectoryServices.DirectorySearcher
        $searcher.Filter = "(&(objectClass=computer)(dNSHostName=$currentDomain))"
        $searcher.SearchRoot = "LDAP://" + $currentDomain + "/OU=Domain Controllers," + $defaultNamingContext
        $dcObjectPath = $searcher.FindAll() | %{$_.Path}

        # DFSR
        $searchDFSR = New-Object DirectoryServices.DirectorySearcher
        $searchDFSR.Filter = "(&(objectClass=msDFSR-Subscription)(name=SYSVOL Subscription))"
        $searchDFSR.SearchRoot = $dcObjectPath
        $dfsrSubObject = $searchDFSR.FindAll()

        if ($dfsrSubObject -ne $null){

            [pscustomobject]@{
                "SYSVOL Replication Mechanism"= "DFSR"
                "Path:"= $dfsrSubObject|%{$_.Properties."msdfsr-rootpath"}
            }

        }

        # FRS
        $searchFRS = New-Object DirectoryServices.DirectorySearcher
        $searchFRS.Filter = "(&(objectClass=nTFRSSubscriber)(name=Domain System Volume (SYSVOL share)))"
        $searchFRS.SearchRoot = $dcObjectPath
        $frsSubObject = $searchFRS.FindAll()

        if($frsSubObject -ne $null){

            [pscustomobject]@{
                "SYSVOL Replication Mechanism" = "FRS"
                "Path" = $frsSubObject|%{$_.Properties.frsrootpath}
            }

        }