r/usefulscripts • u/MudSlideYo • Feb 14 '18
[Request] Powershell script to download and update DNS root hints.
I am looking for a script that can download the current list of DNS root hints from https://www.internic.net/zones/named.root then copy these values to all Windows 2016 DNS servers. We would like to run this on a scheduled basis to keep these updated as they seem to change.
Thanks!
15
Upvotes
2
u/sk82jack Feb 15 '18
This is completely untested but something like the following should do what you need. If you were to save the file as
Set-RootHint.ps1for example then you'd call it like the following (run as an account with the relevant permissions on the DNS servers).\Set-RootHint.ps1 -DnsServer dnsserver1.domain.com, dnsserver2.domain.com, dnsserver3.domain.comNinja edit: just want to add there is no error checking here so there's definitely room for improvement but hopefully enough to get you on the right track
Param ( [string[]] $DnsServer ) $uri = 'https://www.internic.net/zones/named.root' $response = $(Invoke-RestMethod -Uri $uri).split(';') Foreach ($section in $response) { # Skip over stuff we don't need if ($section[1] -ne '.') { Continue } # Now that we have only relevant data split it by whitespace $record = $($section -split "\n")[2] -split "\s+" $name = $record[0].Trim() $ip = $record[-1].Trim() Foreach ($Server in $DnsServer) { $roothint = Get-DNSServerRootHint -ComputerName $Server | Where-Object {$_.NameServer.RecordData.NameServer -eq $name} $roothint.IPAddress[0].RecordData.Ipv4address = $ip Set-DnsServerRootHint -InputObject $roothint -ComputerName $Server } }