Active-Directory

如何使用 Powershell 檢查 DFSR 或 FRS 的 Sysvol 複製?

  • May 2, 2022

我一直在研究如何檢查用於 Sysvol 複製的 DFSR 或 FRS 是否與 powershell 一起使用。這是我的幼稚方法,我嘗試過實施。

  1. 檢查是否安裝了 DFS 複製

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

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

那麼,這證明它使用 FRS 而不是 DFSR?

  1. 檢查 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" }

這將返回“FRS”。但是當我仔細檢查$frs$dfsr輸出時。兩者都不是$null。兩者都返回 DN、Name、ObjectClass 和 ObjectGUID。那麼,這裡有什麼問題?

我已經找到了實現這一點的方法,希望對您有所幫助!

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

       }

引用自:https://serverfault.com/questions/876823