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
SiteName = "SomeSite"
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")
Set fso = CreateObject("Scripting.FileSystemObject")
myWorkDir = fso.GetParentFolderName(WScript.ScriptFullName)
filename = myworkdir & "\subnets.csv"
Set tsInputFile = fso.OpenTextFile(filename, ForReading, False)
loopcount = 0
While Not tsInputFile.AtEndOfStream
strLine = tsInputFile.ReadLine
arrInput = Split(strLine, ",")
Description = arrinput (0)
subnetname = arrinput(1) & "/24"
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
Wend
tsInputFile.Close
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
