Short one today, as I’m super busy with regular work. 🙂
At my company we use a dynamic DNS service for load balancing or failover. This is great because clients don’t notice downtime when a failover or load balancing action occurs. It makes everything smooth and fluent for clients and users of our systems.
The only problem with this is that sometimes a failover occurs and you don’t notice. Great for users, not so great for administrators; if a server crashes in the woods, did it really crash at all?
To make sure we always get notified about these situations we use the following script via our RMM system.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
$DomainsToTest = @("remote.clientname.com", "clientswebsite.com")
New-item "C:\ProgramData\DNSTestLog" -ItemType Directory -erroraction SilentlyContinue -Force | out-null
$DNSHealth = foreach ($DomainToTest in $DomainsToTest) {
Clear-DnsClientCache
$PreviousDNS = get-content "C:\ProgramData\DNSTestLog\$($DomainToTest).txt" -ErrorAction SilentlyContinue
if (!$PreviousDNS) {
write-host "No previous file found. Creating file. Compare will fail."
"" | Out-File "C:\ProgramData\DNSTestLog\$($DomainToTest).txt"
}
$DNSResults = (Resolve-dnsname -name $DomainToTest -Type A -NoHostsFile).IP4Address
$DNSResults | Out-File "C:\ProgramData\DNSTestLog\$($DomainToTest).txt"
if ($PreviousDNS -ne $DNSResults) {
"$DomainToTest does not equal the previous result."
}
}
if (!$DNSHealth) {
$DNSHealth = "Healthy"
}
|
And that’s it! as always, Happy PowerShelling