Title: Active Directory Subnets
When I look at this problem vbs scripting seem the best method.  Below is the script that we used to add about 60 subnets into our AD.  Reads from a csv file and is set to run for one site, however, you could modify it to read the site out of the csv file.  It is based on the script from the MS site.  Worked for us, but usual "use at your own risk" caveats apply. 
 
-Stuart Fuller
State of Montana
 
--------------------------------
'Setup and define variables
Option Explicit
Const adStateOpen = 1
Const ForReading = 1
DIM Sitename,SubnetName,Root
DIM ConfigurationRoot,SitesRoot
DIM SubnetsRoot,NewSubnet
DIM thisSite,Description
DIM fso,tsinputfile,myworkdir,filename
DIM arrInput,strline
DIM loopcount
 
' The Site to create subnets for
SiteName   = "SomeSite"
'Set the function calls
Set Root = GetObject("LDAP://RootDSE")
ConfigurationRoot = Root.Get("configurationNamingContext")
Set Root = GetObject("LDAP://" & ConfigurationRoot)
Set SitesRoot = Root.GetObject("sitesContainer", "CN=Sites")
set SubnetsRoot = SitesRoot.GetObject("subnetsContainer","CN=Subnets")
 
'Open the csv file for reading and set work directory
Set fso = CreateObject("Scripting.FileSystemObject")
myWorkDir = fso.GetParentFolderName(WScript.ScriptFullName)
filename = myworkdir & "\subnets.csv"
Set tsInputFile = fso.OpenTextFile(filename, ForReading, False)
 
'Start of loop and set counter to double check csv file is being read
loopcount = 0
While Not tsInputFile.AtEndOfStream
 
'read file and set values
strLine = tsInputFile.ReadLine
arrInput = Split(strLine, ",")
Description = arrinput (0)
subnetname = arrinput(1) & "/24"
 
'Create object
set NewSubnet = SubnetsRoot.Create("subnet", "CN=" & SubnetName)
set thisSite  = SitesRoot.GetObject("site", "CN=" & SiteName)
NewSubnet.Put "siteObject", thisSite.Get("distinguishedName")
NewSubnet.Put "Description", Description
NewSubnet.SetInfo
Set NewSubnet = Nothing
Description = ""
subnetname = ""
loopcount = loopcount + 1
 
'END OF LOOP
Wend
 
'Close file
tsInputFile.Close
 
'Display end
msgbox ("Script done! " & loopcount & " objects created.")
 


From: Crenshaw, Jason [mailto:[EMAIL PROTECTED]
Sent: Wednesday, July 23, 2003 7:40 AM
To: '[EMAIL PROTECTED]'
Subject: [ActiveDir] Active Directory Subnets

I have a question about AD Subnets and programmatically adding them to Sites.  We have a rather large list of subnets that need to be assigned to Sites and I didn't want to hand-to-hand combat those entries if possible.

I was looking at using this script I found at Microsoft, but was wondering what some other AD sites have done in the past.  Or maybe someone has a better suggestion than the script below.

Thanks,

Jason

Creating an Active Directory Subnet

Description
Creates an Active Directory subnet.

Script Code

strSubnetRDN     = "cn=192.168.1.0/26"

strSiteObjectRDN = "cn=Ga-Atl-Sales"

strDescription   = "192.168.1.0/255.255.255.192"

strLocation      = "USA/GA/Atlanta"

Set objRootDSE = GetObject("LDAP://RootDSE")

strConfigurationNC = objRootDSE.Get("configurationNamingContext")

strSiteObjectDN = strSiteObjectRDN & ",cn=Sites," & strConfigurationNC

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

Set objSubnetsContainer = GetObject(strSubnetsContainer)

Set objSubnet = objSubnetsContainer.Create("subnet", strSubnetRDN)

objSubnet.Put "siteObject",  strSiteObjectDN

objSubnet.Put "description", strDescription

objSubnet.Put "location",    strLocation

objSubnet.SetInfo      

Reply via email to