Adding 2016 subnets to AD Sites and Services

In a recent post I showed how to configure the DHCP server with multiple scopes of subnets with PowerShell and how blazing fast that could be done in the Windows 2012 compared to Windows 2008 R2.

One thing we might forget is to populate the Active Directory Sites and Services subnets with this information to get the clients to access the domain controllers that is nearest. As you can read in this technet post the reason for populating this:

“Domain controllers register service (SRV) resource records in Domain Name System (DNS) that identify their site names. Domain controllers also register host (A) resource records in DNS that identify their IP addresses. When a client requests a domain controller, it provides its site name to DNS. DNS uses the site name to locate a domain controller in that site (or in the next closest site to the client). DNS then provides the IP address of the domain controller to the client for the purpose of connecting to the domain controller. For this reason, it is important to ensure that the IP address that you assign to a domain controller maps to a subnet that is associated with the site of the respective server object. Otherwise, when a client requests a domain controller, the IP address that is returned might be the IP address of a domain controller in a distant site. When a client connects to a distant site, the result can be slow performance and unnecessary traffic on expensive WAN links.”

So as we do not want to update 2016 subnets manually we do this with PowerShell instead, and as you can see with the Windows 2012 it goes quite fast (I have tested on Win 2008 R2 and it works there also).

sitesps

and here is the small PowerShell bits that do the magic

# Populate Subnets in AD Sites and Services
#
# Niklas Akerlund 2013-05-14 

for($b=1;$b -le 63 ; $b++){
    for($i=0;$i -le 255){ 
        $Name = "10.10.$b.$i" + "/29"
        $Description = "10.10.$b.$i" + "/255.255.255.248"
        New-ADObject -Name $Name -Type subnet -Description $Description -OtherAttributes @{location="RemoteVPN";siteObject="CN=HQ,CN=Sites,CN=Configuration,DC=lumademo,DC=local"} -Path "CN=Subnets,CN=Sites,CN=Configuration,DC=lumademo,DC=local"     
        $i = $i +8
    }
}

And then when you look in the Active Directory Sites and Services you will find all the subnets and that they correlate to the right site.

sitesservice

Leave a comment

name*

email* (not published)

website