# Script to test AD-Replication # It modifies a given text-property of a given object # first it reads the timestamp. if there is no stamp it adds one # calculate the delta between now and last run für later comparison # foreach DC: if timestamp delta + lastrundelta larger maxlatency, notify # at the end. Update the timestamp at the source für next run # planned enhancements # Mail Notification, Eventlog # Awareness of sites (more delay # using DC as default objkect an running against all DCs param ( $testobjectdn = "dc=netatwork,dc=de", # dn to the testobject. Object must exist $testproperty = "description", # object property to write to. must be string $sourceserver = "nawdc003", # DC to write to $targetserver = ("nawdc001","nawdc002"), # DCs to read $lastrunwarning = 600, # generate warning if sourcetimestamp older than $maxlatency = 120 # minimum time to wait für start checking ) Write-Host "test-adrepl: ------- starting ------- " # read current timestamp [adsi]$sourceobj = [adsi]"LDAP://$sourceserver/$testobjectdn" if ($sourceobj.path -eq $null ){ Write-host "Unable to connect to LDAP://$sourceserver/$testobjectdn" -BackgroundColor red -ForegroundColor White } else { Write-host " Bound " $sourceobj.path [datetime]$now = Get-Date write-host " Current local time" (get-date -Format o) [string]$timestamp = $sourceobj.$testproperty if ($timestamp -eq ""){ Write-host " Timestamp empty. Initial run" -BackgroundColor Yellow -foreground black [string]$timestamp = (get-date -Format o) $sourceobj.$testproperty = $timestamp $sourceobj.setinfo() Write-host " Timestamp generated" -BackgroundColor green -foreground black } else { write-host " Timestamp Source: $timestamp" [datetime]$lastrun = $timestamp $lastrundelta = ($now - $lastrun).totalseconds write-host " Delta to last run: $lastrundelta seconds" if ($lastrundelta -ge $lastrunwarning) { Write-Host "ATTN: Lastrun $lastrundelta longer than $lastrunwarning" -BackgroundColor red -ForegroundColor White } Write-Host "Testing other servers" -BackgroundColor Green -foreground black foreach ($dc in $targetserver) { Write-Host "Connecting to: " $dc [adsi]$testobj = [adsi]"LDAP://$dc/$testobjectdn" write-host " Bound" $testobj.path [string]$teststamp = $testobj.$testproperty write-host " Timestamp on Target:" $teststamp [datetime]$timestamp = $teststamp $latency = [int](($now - $timestamp).totalseconds) if ($latency -ge ($maxlatency+$lastrundelta)){ Write-Host "ATTN: Timestamp to old. Latency:$latency" -BackgroundColor red -ForegroundColor White } else { Write-Host "OK: Timestamp ok. Latency:$latency" -BackgroundColor Green -ForegroundColor black } } Write-Host "Updateing Stimestamp" [string]$timestamp = (get-date -Format o) $sourceobj.$testproperty = $timestamp $sourceobj.setinfo() } } Write-Host "test-adrepl: ------- End ------- "