Listing04_Create_Site (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
'# Copyright (C) 2002 by Addison-Wesley
'# Script by Robbie Allen
'# 
'# You have a royalty-free right to use, modify, reproduce and distribute
'# this script (and/or any modified version) in any way you find useful,
'# provided that you agree that Addison-Wesley or Robbie Allen has no
'# warranty, obligations or liability for the script. If you modify
'# the script, you must retain this copyright notice.
'# -----------------------------------------------------------------------------
Dim new_site, new_site_rdn, user, passwd, server, new_site_dn, sites_dn
Dim sitesObj, ldapObj, siteObj, servObj, ntdsObj, licObj

new_site = "RTP"

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

' This could be dynamically retrieved using RootDSE
sites_dn    = "cn=sites,cn=configuration,dc=xyz,dc=com"
new_site_rdn = "cn=" & new_site

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

Wscript.Echo "Creating site object for " & new_site
Set siteObj = sitesObj.Create("site", new_site_rdn)
siteObj.SetInfo()
Wscript.Echo "Done"

Wscript.Echo "Creating servers container"
Set servObj = sitesObj.Create("serversContainer", _
                            "cn=Servers," & new_site_rdn)
servObj.SetInfo()
Wscript.Echo "Done"

Wscript.Echo "Creating NTDS Site Settings object"
Set ntdsObj = sitesObj.Create("nTDSSiteSettings", _
                           "cn=NTDS Site Settings," & new_site_rdn)
ntdsObj.SetInfo()
Wscript.Echo "Done"

Wscript.Echo "Creating Licensing Site Settings object"
Set licObj = sitesObj.Create("licensingSiteSettings", _
                             "cn=Licensing Site Settings," & new_site_rdn)
licObj.SetInfo()
Wscript.Echo "Done"

Wscript.Echo "Site creation complete"

This code has been viewed 754 times.

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