How can I create a list of all subnets in a forest that aren't assigned to a site?

John Savill

March 19, 2006

1 Min Read
ITPro Today logo in a gray background | ITPro Today

A. By default, when you create a subnet via the Microsoft Management Console (MMC) Active Directory Sites and Services snap-in, you must link it to a site. However, after the subnet is created, you can unlink it from a site, as the figureshows. You can use the following script, which you can download here, to list subnets that aren't linked to a site.

' listsubnetnosite.vbs' John Savill' Usage : listsubnetnosite.vbs' e.g. cscript listsubnetnosite.vbson error resume nextSet objRootDSE = GetObject("LDAP://RootDSE")strConfigurationNC = objRootDSE.Get("configurationNamingContext")strSubnetsContainer = "LDAP://cn=Subnets,cn=Sites," & strConfigurationNCSet objSubnetsContainer = GetObject(strSubnetsContainer)objSubnetsContainer.Filter = Array("subnet")For Each objSubnet In objSubnetsContainer    objSubnet.GetInfoEx Array("siteObject"), 0    objSubnet.Get("siteObject")    If Err.number  0 Then        WScript.Echo mid(objSubnet.Name,4) ' & " " & Err.description        Err = 0    End IfNext

To run the script, execute it without any parameters, as this example shows:

C:temp>cscript listsubnetnosite.vbs

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like