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

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.vbs

on error resume next

Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")

strSubnetsContainer = "LDAP://cn=Subnets,cn=Sites," & strConfigurationNC

Set objSubnetsContainer = GetObject(strSubnetsContainer)

objSubnetsContainer.Filter = Array("subnet")

For Each objSubnet In objSubnetsContainer
    objSubnet.GetInfoEx Array("siteObject"), 0
    If Err.number  0 Then
        WScript.Echo mid(objSubnet.Name,4) ' & " " & Err.description
        Err = 0
    End If
To run the script, execute it without any parameters, as this example shows:

C:\temp>cscript listsubnetnosite.vbs
Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.