PC Review


Reply
Thread Tools Rate Thread

Adding subnets to AD

 
 
Robin Briggs
Guest
Posts: n/a
 
      26th Jan 2004
I have found a useful code snipet on the MS web site to
add subnets to AD Sites & Services. Works well for one
subnet as you have to enter the subnet information into
the script. I have to add 1,000+ subnets and would prefer
to be able to specify an input file rather than having to
cut/past or type this information for each subnet into
the script, one at a time. I have a csv file that
contains the subnet name, siteobject name and description
which is all I want to enter for each subnet.

The code I am using is as follows:
strSubnetRDN = "cn=192.168.1.0/26"
strSiteObjectRDN = "cn=USA-SITE1"
strDescription = "Bldg. 1, Rochester, NY"

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.SetInfo

Any help anyone can offer is appreciated.
 
Reply With Quote
 
 
 
 
nut cracker
Guest
Posts: n/a
 
      26th Jan 2004
I dont speak VBscript, but i do speak perl.

read the contents from the text file into an refernce to a file object.
Then, based on the position in the array (multidimentional), feed that into
a " for each " loop that puts the values into the script. loop through until
there are no values in the array

wash, rinse, repeat.


In perl I would do (somthing like) this:

$args = $ARGV[0]; #takes the name of the file and gives it a reference
open(ARGS, "$args"); #opens a filehandle based on the ref
while(defined($line=<ARGS>)){
@array = $line;
$array[0] = strSubnetRDN;
$array[1] = strSiteObjectRDN;
$array[3] = strDescription

# use the data from the array ordinal reference above

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.SetInfo
}


the "while" line will be executed as though it were reading one line at a
time from your data file, and when it reaches the end (thus not being
defined), it will stop.

other logic and steps could be added to print results of each add into a log
file to check for any problems. This should just give you an idea of how it
can be done with a loop.

NuTs




"Robin Briggs" <(E-Mail Removed)> wrote in message
news:420c01c3e43a$12150770$(E-Mail Removed)...
> I have found a useful code snipet on the MS web site to
> add subnets to AD Sites & Services. Works well for one
> subnet as you have to enter the subnet information into
> the script. I have to add 1,000+ subnets and would prefer
> to be able to specify an input file rather than having to
> cut/past or type this information for each subnet into
> the script, one at a time. I have a csv file that
> contains the subnet name, siteobject name and description
> which is all I want to enter for each subnet.
>
> The code I am using is as follows:
> strSubnetRDN = "cn=192.168.1.0/26"
> strSiteObjectRDN = "cn=USA-SITE1"
> strDescription = "Bldg. 1, Rochester, NY"
>
> 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.SetInfo
>
> Any help anyone can offer is appreciated.



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding subnets =?Utf-8?B?Skh1bGw=?= Microsoft Windows 2000 Active Directory 2 16th Apr 2006 10:43 PM
Adding new subnets =?Utf-8?B?cnN0dXR0ZQ==?= Microsoft Windows 2000 Networking 4 8th Aug 2005 09:49 PM
VPN and subnets Evan Windows XP Work Remotely 0 4th Feb 2004 11:08 PM
Multiple subnets/4 subnets share the same switch/hub. Joe M Microsoft Windows 2000 Networking 1 26th Oct 2003 02:34 AM
Multiple subnets/4 subnets share the same switch/hub. Joe M Microsoft Windows 2000 RAS Routing 1 26th Oct 2003 02:34 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:52 AM.