Listing08_Create_Subnet (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 new_subnet, subnet_site, user, passwd, server, sites_dn
Dim siteObj, ldapObj, subnetObj

new_subnet = "10.5.5.0/24"
subnet_site = "RTP"

server = "dc1.xyz.com"
user   = "administrator@xyz.com"
passwd = "password"

' This could be dynamically computed using RootDSE
sites_dn = "cn=sites,cn=configuration,dc=xyz,dc=com"

Set ldapObj  = GetObject("LDAP:")
Set sitesObj = ldapObj.OpenDsObject("LDAP://" & server & "/" & sites_dn, _
                                    user, passwd, 1)

Wscript.Echo "Creating subnet " & new_subnet
Set subnetObj = sitesObj.Create("subnet","cn=" & new_subnet & ",cn=Subnets")
subnetObj.Put "siteObject","cn=" & subnet_site & "," & sites_dn
subnetObj.SetInfo()
Wscript.Echo "Subnet creation complete"

This code has been viewed 764 times.

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