GPO: Advanced DNS Manipulation

So back in August I needed a way for GPO to force a primary and secondary DNS server. This is great, but what do I do when I have multiple sites with obviously different DNS settings? The answer? Write a script that checks for the AD Site location and then configures the DNS settings based on where the server is located. For example, a server in Morocco should point to a Moroccan DNS server first, not a server located at the headquarters in Belgium.

In this example 10.4.12.31 = Morocco DNS Server (DC) and 10.23.3.12 = Belgium DNS Server (DC).

As you can also see in my script,
else
Wscript.Echo “ELSE EEF AD Site: “ & vbTab & strSiteLocation & vbCr _

If you have multiple sites you would replace this with an elseif and check the existence of another site in the registry – then apply DNS settings based on that location.

DNS v1.1
‘ August 11, 2006 – - Jason Langone
‘ This script will add the DNS suffixes listed below to the search order.
‘ This script will also make MORODC2 primary DNS and BELGDC1 secondary.
‘ Script now checks for Site location via registry read.

‘Start of AD Site Determination.
‘Option Explicit
Dim objShell
Dim strSiteLocation, strRegistry
strSiteLocation = “DynamicSiteName”
strRegistry = “HKLM\SYSTEM\ControlSet001\”_
& “Services\Netlogon\Parameters\”
Set objShell = CreateObject(“WScript.Shell”)
strSiteLocation = objShell.RegRead(strRegistry & strSiteLocation)
‘ End of AD Site Determination.
‘ Start of DNS settings
if strSiteLocation=“Morocco” then
SET WSHShell = CreateObject(“WScript.Shell”)
WSHShell.RegWrite “HKLM\System\CurrentControlSet\Services\TCPIP\Parameters\SearchList”, “morocco.fake.com, outerspace.fake.com,fake.com”, “REG_SZ”
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)

Set colNetCards = objWMIService.ExecQuery _
(“Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True”)

For Each objNetCard in colNetCards
arrDNSServers = Array(“10.4.12.31”, “10.23.3.12”)
objNetCard.SetDNSServerSearchOrder(arrDNSServers)
Next
else
Wscript.Echo “ELSE EEF AD Site: “ & vbTab & strSiteLocation & vbCr _
end if
WScript.Quit

- Jason Langone

Posted on Sep 19, 08:56 AM by Jason Langone

Commenting is closed for this article.

Commenting is closed for this article.