Listing10_Iterate_Subnets (VBScript)

This code can be found in Chapter 9 of Managing Enterprise Active Directory Services

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

'# From the book "Managing Enterprise Active Directory Services"
'# ISBN: 0-672-32125-4

Dim user, passwd, server, subnets_dn, ldapObj, subnetsObj, subnetObj
Dim count, site_dn, regexObj, site

server = "dc1.xyz.com"
user   = "administrator@xyz.com"
passwd = "password"
subnets_dn = "cn=subnets,cn=sites,cn=configuration,dc=xyz,dc=com"

Set ldapObj = GetObject("LDAP:")
Set subnetsObj = ldapObj.OpenDsObject("LDAP://" & server & "/" & subnets_dn, _
                                        user, passwd, 1)
subnetsObj.Filter = Array("subnet")
count = 0
On Error Resume Next
For Each subnetObj in subnetsObj
   count = count + 1
   site_dn = subnetObj.Get("siteObject")
   ' strip off everything but the name from the site DN
   Set regexObj = New RegExp
   regexObj.Pattern = "^cn=(.+),cn=sites,cn=configuration,.+$"
   regexObj.IgnoreCase = True
   site = regexObj.Replace(site_dn,"$1")
   Wscript.Echo count & ". " & subnetObj.cn & " (" & site & ")"
Next

This code has been viewed 838 times.

New from the creators of TechTasks.com: StatSheet.com