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(, “/”)
If Instr(sResult.siteObject, “,”) = 0 Then
sSN = aSNInfo(0)
sSN = aSNInfo(0) & “,” & _
Mid(Left(sResult.siteObject, Instr(sResult.siteObject, “,”) – 1), 4)
End if
wscript.echo ssn

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:\support\listsites.vbs > c:\support\sitelist.csv

One Response to “List Active Directory sites and their associated subnets”

  1. David says:

    It works very well.
    Thanks for your post.

    David from France.

Leave a Reply