DFS Replication Backlog PowerShell Script

If you have information, script, utility, or idea that can be useful for HostMonitor community, you welcome to share information in this forum.
Post Reply
PaulNZ
Posts: 9
Joined: Tue Apr 04, 2017 7:31 pm

DFS Replication Backlog PowerShell Script

Post by PaulNZ »

Cobbled this together from some stuff I found online.

Name: PowerShell: Get DFS-R Backlog
Hint: Params: <Group Name> <Folder Name> <Sending Member> <Receiving Member> <Backlog Threshold>

Start cmd: powershell.exe %script% %params%
Script:

Code: Select all

$statusAlive       = "ScriptRes:Host is alive:"
$statusDead        = "ScriptRes:No answer:"
$statusUnknown     = "ScriptRes:Unknown:"
$statusNotResolved = "ScriptRes:Unknown host:"
$statusOk          = "ScriptRes:Ok:"
$statusBad         = "ScriptRes:Bad:"
$statusBadContents = "ScriptRes:Bad contents:"

if (!$args[4]) {
  echo  $statusUnknown"Insufficient parameters provided"
  exit
}

$ReplicationGroupName = $args[0]
$ReplicatedFolderName = $args[1]
$Smem = $args[2]
$Rmem = $args[3]
$BacklogThreshold = $args[4]

$WMIQuery = "SELECT * FROM DfsrReplicatedFolderInfo WHERE ReplicationGroupName = '" + $ReplicationGroupName + "' AND ReplicatedFolderName = '" + $ReplicatedFolderName + "'"
$OutboundPartnerWMI = Get-WmiObject -computername $Smem -Namespace "root\MicrosoftDFS" -Query $WMIQuery
$InboundPartnerWMI = Get-WmiObject -computername $Rmem -Namespace "root\MicrosoftDFS" -Query $WMIQuery
$VersionVector = $InboundPartnerWMI.GetVersionVector().VersionVector
$BacklogCount = $OutboundPartnerWMI.GetOutboundBacklogFileCount($VersionVector).BacklogFileCount

if ($BacklogCount -le $BacklogThreshold) 
{
   echo $statusOk$BacklogCount" Files"
} 
else 
{
   echo $statusBad$BacklogCount" Files"
}
Post Reply