2

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?

Ender
  • 604
  • 3
  • 9
  • 13
  • The `Get-WindowsFeature` just shows all available Windows features. In your example the `[ ]`, and `Install State 'Available'`, indicates the feature is available but not installed. An installed feature will have will appear as `[X]` with `Install State 'Installe'`. Try `Get-WindowsFeature | ? { $_.'InstallState' -eq 'Installed' }`. Moreoever, the general utility for querying FRS migration is `Dfsrmig /getmigrationstate`. – jscott Oct 04 '17 at 11:57
  • I edited my answer. – Sorcha Oct 04 '17 at 12:23
  • @Sorcha tks for the answer. I knew the `Get-WindowsFeature` properties and so on. I have tried to run the `Dfsrmig /getmigrationstate`. It returns nothing. @jscott – Ender Oct 04 '17 at 13:51

3 Answers3

2

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}
            }

        }
Ender
  • 604
  • 3
  • 9
  • 13
1

Mind Windows Server 2022 has removed dfsrmig.exe so you can only check whether the FRS or DFS-R Service is running on all Domain Controllers. Additionally starting with Windows Server 2022 it is required to have DFS-R, while previous OS only gave a warning.

You could now use

Get-DfsReplicationGroup -IncludeSysvol 

to check if it does list the "Domain System Volume" replication group.

(Get-ADDomainController -Filter *).name | ForEach-Object -Process {Get-Service -ComputerName $_ -Name DFSR,NTFRS} | Sort-Object DisplayName

to check the services. FRS should be disabled and DFSR should be running.

1

If you want to check your DFS replication with powershell, you could use the appropriate cmdlets :

PS C:\> get-command -Name "*dfsr*"

CommandType     Name                                               ModuleName                                                                                       
-----------     ----                                               ----------                                                                                       
Cmdlet          Add-DfsrConnection                                 DFSR                                                                                             
Cmdlet          Add-DfsrMember                                     DFSR                                                                                             
Cmdlet          ConvertFrom-DfsrGuid                               DFSR                                                                                             
Cmdlet          Export-DfsrClone                                   DFSR                                                                                             
Cmdlet          Get-DfsrBacklog                                    DFSR                                                                                             
Cmdlet          Get-DfsrCloneState                                 DFSR                                                                                             
Cmdlet          Get-DfsrConnection                                 DFSR                                                                                             
Cmdlet          Get-DfsrConnectionSchedule                         DFSR                                                                                             
Cmdlet          Get-DfsReplicatedFolder                            DFSR                                                                                             
Cmdlet          Get-DfsReplicationGroup                            DFSR                                                                                             
Cmdlet          Get-DfsrFileHash                                   DFSR                                                                                             
Cmdlet          Get-DfsrGroupSchedule                              DFSR                                                                                             
Cmdlet          Get-DfsrIdRecord                                   DFSR                                                                                             
Cmdlet          Get-DfsrMember                                     DFSR                                                                                             
Cmdlet          Get-DfsrMembership                                 DFSR                                                                                             
Cmdlet          Get-DfsrPreservedFiles                             DFSR                                                                                             
Cmdlet          Get-DfsrServiceConfiguration                       DFSR  

In particular, Get-DfsrBacklog to check if you have files waiting for replication:

PS C:\Windows\system32> (Get-DfsrBacklog -SourceComputerName Server1 -DestinationComputerName Server2).count
4

It will give the number of waiting files, and more generally, which file... You can invert the source and destination to get the replication state of the other side.

Edit comment

You can use dfsrmig.exe /GetGlobalState to test which replication is used. If the command return 'dfsr not initalized', you use FSR.

Sorcha
  • 1,315
  • 8
  • 11