$LargestDeltaTreshold = 20 $repadmin = repadmin /replsum /bydest [regex]$regex = '\s+(?\S+)\s+(?\S+)\s+(?\d{1,2}\s)' [regex]$regex2 = '\s+(?\d{1,2}\S+)\s\-\s+(?\S+)' $repadmin | ForEach-Object { if ( $_ -match $regex ) { $process = "" | Select-Object DC, Delta, fail $process.dc = $matches.dc $process.Delta = $matches.Delta $process.fail = [int]($matches.fail) $VdayTime = 0 $VHourTime = 0 $VMinutesTime = 0 if ($process.Delta.contains("d")) { $VdayTime = [int]($process.Delta.substring(0,2)) $VHourTime = [int]($process.Delta.substring(4,2)) $VMinutesTime = [int]($process.Delta.substring(8,2))} Else { if ($process.Delta.contains("h")) { $VHourTime = [int]($process.Delta.substring(0,2)) $VMinutesTime = [int]($process.Delta.substring(4,2))} Else { if ($process.Delta.contains("m")) { $VMinutesTime = [int]($process.Delta.substring(0,2))} } } $DeltaMinutes = New-TimeSpan -Days $VdayTime -Hours $VHourTime -Minutes $VMinutesTime if (($DeltaMinutes.Minutes -gt $LargestDeltaTreshold) -or ($process.fail -gt 0)) { write-host $process.dc "Largest Delta:" $DeltaMinutes.Minutes "minutes, Total errors:" $process.fail $xml = (Get-ADRootDSE -server $process.dc -Properties msDS-ReplAllInboundNeighbors)."msDS-ReplAllInboundNeighbors" $xml = “” + $xml + “” $xml = $xml.Replace([char]0,” ”) $xmlAttributeDocObject = [XML]$xml $ObjectMetadataTableFormatter = @() $ObjectMetadataTableFormatter += @{Label="Replication Partner"; Expression={(Get-ADObject $_.pszSourceDsaDN.Substring(17,$_.pszSourceDsaDN.length-17) -properties dnshostname).DNSHostName}} $ObjectMetadataTableFormatter += @{Label="Naming Context"; Expression = {$_.pszNamingContext}} $ObjectMetadataTableFormatter += @{Label="Last Time sucess"; Expression={[datetime]::parse($_.ftimeLastSyncSuccess)}} $ObjectMetadataTableFormatter += @{Label="C SyncFailures"; Expression={[int]($_.cNumConsecutiveSyncFailures)}} $xmlAttributeDocObject.root.DS_REPL_NEIGHBOR | sort-Object ftimeLastSyncSuccess | ft $ObjectMetadataTableFormatter } } Elseif ( $_ -match $regex2 ) { write-host "Errors trying to retrieve replication information:" $process2 = "" | Select-Object DC,fail $process2.fail = $matches.fail $process2.DC = $matches.DC $process2 } }