How can I use a script to list all subnets in a site?

A. The following script, which you can download here, takes as its first argument the name of a site and returns all the subnets for the given site:

strSiteRDN = "cn=" & WScript.Arguments(0)

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

strSitePath = "LDAP://" & strSiteRDN & ",cn=Sites," & strConfigurationNC

Set objSite = GetObject(strSitePath)

objSite.GetInfoEx Array("siteObjectBL"), 0
arrSiteObjectBL = objSite.GetEx("siteObjectBL")

For Each strSiteObjectBL In arrSiteObjectBL
    WScript.Echo Split(Split(strSiteObjectBL, ",")(0), "=")(1)
Next

The sample command
D:\Temp>cscript listsubnets.vbs Dallas

produces the following output:

192.168.2.0/24
192.168.1.0/24
Hide comments

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