List Active Directory sites and their associated subnets

If you ever need to look up which subnet is associated with which active directory site then just paste the below into vbs and pipe its output to a text file.

‘Get list of AD subnets
Set oRootDSE = GetObject(“LDAP://RootDSE”)
sConfigurationNC = oRootDSE.Get(“configurationNamingContext”)
Set oRootDSE = Nothing
sSubnetsContainer = “LDAP://cn=Subnets,cn=Sites” & “,” & sConfigurationNC
Set oSubnetsContainer = GetObject(sSubnetsContainer)
For Each sResult In oSubnetsContainer
aSNInfo = Split(sResult.cn, “/”)
If Instr(sResult.siteObject, “,”) = 0 Then
sSN = aSNInfo(0)
Else
sSN = aSNInfo(0) & “,” & _
Mid(Left(sResult.siteObject, Instr(sResult.siteObject, “,”) – 1), 4)
End if
wscript.echo ssn
Next

If you name the script listsites.vbs and want to output to a file call sitelist.csv and the script sites in a folder called “support” you can just run the following command line.

cscript c:supportlistsites.vbs > c:supportsitelist.csv

One thought on “List Active Directory sites and their associated subnets

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.