Skip to content

Instantly share code, notes, and snippets.

@Ba4bes
Last active May 31, 2020 17:53
Show Gist options
  • Save Ba4bes/ef101b1a3e98eda96fab66a9dd824edc to your computer and use it in GitHub Desktop.
Save Ba4bes/ef101b1a3e98eda96fab66a9dd824edc to your computer and use it in GitHub Desktop.
Example for https://4bes.nl, not meant for production
#######################################
#Monitor DFSR replication
#Created by: Barbara Forbes
#Date: 26-2-2016
####################################
#The account running this script needs to have permissions on the drives that are used for this test.
#Define Paths on both servers, change this to your situation
$DFSpath1 = "c:\test"
$DFSpath2 = "c:\temp"
#Define time till warning or error state. Default is 60 seconds.
$Secondstillerror = 60
#build strings for filename
$timef = ((get-date).tostring("ddMMyyyyHHmmss"))
#Create a filename with a time-reference
$filetime = Get-Date -uformat "%d-%m-%Y %T"
$testfilename = "TestDFSR$timef"
$DFSRtestfile1 = "$DFSpath1\$testfilename.txt"
#variables to test the path
$Testpath1 = Test-Path $DFSpath1
$Testpath2 = Test-Path $DFSpath2
#check if Path1 exists and permissions are correct
if ($Testpath1 -eq $True){
#continue script
{continue}
}
Else {
Write-host "Path one doesn't exist or no permission to access this path"
exit
}
write-host "number 1 exists :D"
#check if Path 2 exists and permissions are correct
if ($Testpath2 -eq $True){
#continue script
{continue}
}
Else {
Write-host "Path two doesn't exist or no permission to access this path"
exit
}
write-host "number 2 exists :D"
#create testfile on server1
New-Item -Path $DFSRtestfile1 -Type file -Value "This file is safe to delete. Timestamp:$filetime"
#sVariable to check if file exists on server2
$DFSRtestfile2 = "$DFSpath2\$testfilename.txt"
$testpath = Test-Path $DFSRtestfile2
#Try for some time if the file exists on server2
$timeout = new-timespan -seconds $secondstillerror
$sw = [diagnostics.stopwatch]::StartNew()
while ($sw.elapsed -lt $timeout){
if (test-path $DFSRtestfile2){
#File is found, return result
write-host "(0):Found a file!"
Write-Output "Replication is working"
#delete testfiles
Remove-Item -Path $DFSRtestfile1
Remove-Item -Path $DFSRtestfile2
return
}
start-sleep -seconds 5
}
#File is not found, return result. Testfile is kept for monitoring
write-host "Timed out"
Write-Output "Replication not working"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment