我一直在研究如何使用 powershell 检查 Sysvol 复制的 DFSR 或 FRS。以下是我尝试实施的简单方法。
- 检查是否安装了 DFS 复制
PS C:> Get-WindowsFeature|其中 Displayname -Match “复制”
Display Name Name Install State
------------ ---- -------------
[ ] DFS Replication FS-DFS-Replication Available
那么,这证明它使用的是 FRS 而不是 DFSR???
检查 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。那么,这里有什么问题?
答案1
我已经找到了实现这一目标的方法,希望对您有所帮助!
$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}
}
}
答案2
如果您想使用 powershell 检查您的 DFS 复制,您可以使用适当的 cmdlet:
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
特别是Get-DfsrBacklog
检查是否有等待复制的文件:
PS C:\Windows\system32> (Get-DfsrBacklog -SourceComputerName Server1 -DestinationComputerName Server2).count
4
它将给出等待文件的数量,更一般地说,哪个文件...您可以反转源和目标以获取另一端的复制状态。
编辑评论
您可以使用dfsrmig.exe /GetGlobalState
它来测试使用了哪个复制。如果命令返回“dfsr not initalized”,您使用 FSR。
答案3
请注意,Windows Server 2022 已删除 dfsrmig.exe,因此您只能检查 FRS 或 DFS-R 服务是否在所有域控制器上运行。此外,从 Windows Server 2022 开始,需要有 DFS-R,而以前的操作系统只发出警告。
您现在可以使用
Get-DfsReplicationGroup -IncludeSysvol
检查它是否列出了“域系统卷”复制组。
(Get-ADDomainController -Filter *).name | ForEach-Object -Process {Get-Service -ComputerName $_ -Name DFSR,NTFRS} | Sort-Object DisplayName
检查服务。FRS 应被禁用,并且 DFSR 应正在运行。