AllExperts > VB Script 
Search      
VB Script
Volunteer
Answers to thousands of questions
 Home · More VB Script Questions · Answer Library  · Encyclopedia ·
More VB Script Answers
Question Library

Ask a question about VB Script
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Subbu
Expertise
I can answer VB Script questions which are related to Visual Basic / VBA / QTP Scripts.

Experience
8 Years

Education/Credentials
Master of Computer Applications

Awards and Honors
Established Member from QA Forums and Brainbench certification

 
   

You are here:  Experts > Computing/Technology > Basic > VB Script > Subnets script

VB Script - Subnets script


Expert: Subbu - 5/5/2009

Question
QUESTION: Hi , I contacted you yesterday with a problem with subnets and sorry it was my mistake the script was not working. So I have another script which creates subnets from a text documest, assigns them to the same site and puts the same description. Here is the script :

On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Const FOR_APPENDING = 8
Const FOR_READING = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Admin\script for creating subnets\brso01_colombia_1stwave.txt", FOR_READING)

Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")
strDescription = "Bogota, Colombia "


Do Until objFile.AtEndOfStream
   strNextLine = objFile.Readline
   arrServiceList = Split(strNextLine , ",")
   For i = 0 to Ubound(arrServiceList)
  strSiteObjectRDN = "cn=brso01"
  strSiteObjectDN = strSiteObjectRDN & ",cn=Sites," & strConfigurationNC
  strSubnetsContainer = "LDAP://cn=Subnets,cn=Sites," & strConfigurationNC

  Set objSubnetsContainer = GetObject(strSubnetsContainer)

  Set objSubnet = objSubnetsContainer.Create("subnet", "cn="&arrServiceList(i))
  objSubnet.Put "siteObject", strSiteObjectDN
  objSubnet.Put "description", strDescription
  objSubnet.SetInfo
         
   Next

Loop

This script is working for shure.
Can you please help me with this script because I want to change it just to assign subnets from the listg to another site, not to create them.
Thank you very very much!

ANSWER: Hi Raducu,

I need some information from you.

What your brso01_colombia_1stwave.txt file contains.  I mean each line has single subnet masks? (Yes/No).

If Yes then you dont need to split your single line value and not needed For Loop.

If you have still problem then please email a single line in your txt file.

Regards
Subbu.



---------- FOLLOW-UP ----------

QUESTION: The file contains a subnet on each line, with no header, like this:
10.123.124.0/24
10.145.213.0/24
and so on...
This script I use for creating subnets and it works very fine but I want to modify the script to only assign the subnets from the file ( the subnets are already created in Active Directory) to another site.
The site is contained here
strSiteObjectRDN = "cn=brso01"

I think yhis is the part that needs to be modified:
Set objSubnetsContainer = GetObject(strSubnetsContainer)

Set objSubnet = objSubnetsContainer.Create("subnet", "cn="&arrServiceList(i))
objSubnet.Put "siteObject", strSiteObjectDN
objSubnet.Put "description", strDescription
As I can see, after creating the object the script edits the attributes ( siteObject and description), but I want just to edit the site attribute of the subnets in the .txt file.

Thank you very much!


Answer
You dont need to split the line with ",".  Actually there is no "," in that line.  

You just need
Set objSubnet = objSubnetsContainer.Create("subnet", "cn="&strNextLine) 'here strNextLine variable has 10.123.124.0/24

This variable value will keep on change till end of file.


I just modified your code, try this and let me know.



Do Until objFile.AtEndOfStream
  strNextLine = objFile.Readline
strSiteObjectRDN = "cn=brso01"
strSiteObjectDN = strSiteObjectRDN & ",cn=Sites," & strConfigurationNC
strSubnetsContainer = "LDAP://cn=Subnets,cn=Sites," & strConfigurationNC

Set objSubnetsContainer = GetObject(strSubnetsContainer)

Set objSubnet = objSubnetsContainer.Create("subnet", "cn="&strNextLine)
objSubnet.Put "siteObject", strSiteObjectDN
objSubnet.Put "description", strDescription
objSubnet.SetInfo

Loop


Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.