Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read contents of CSV file and use in VBS 3

Status
Not open for further replies.

TheLad

Technical User
Aug 3, 2001
3,846
GB
Guys

I am trying to automate the creation of local users on local servers (they are workgroup 2003 servers, not in AD) and I have written a script to create the user and do all of the necessary tasks as far as that is concerned. What I would like to do now is have a text CSV file containing information such as Username and Full Name and then have my script read the information from that and create the users accordingly.

Please can anyone help me out with how to read from a text CSV file and then pass the information to the script to action? The CSV file would only contain two items per line: Username,Full Name. (Password not required for the CSV file)

Thanks in advance.

--------------------------------------------------------------------------
"Who is General Failure and what is he doing on my computer?"
--------------------------------------------------------------------------
 
Use a SPLIT command.

Code:
dim fs,objTextFile
set fs=Server.CreateObject("Scripting.FileSystemObject")
dim arrStr
set objTextFile = fs.OpenTextFile("Somefile.csv")

Do while NOT objTextFile.AtEndOfStream
  arrStr = split(objTextFile.ReadLine,",")
'  arrStr is now an array that has each of your fields
' process them, whatever.....
Loop

objTextFile.Close
set objTextFile = Nothing
set fs = Nothing



Just my 2¢

"In order to start solving a problem, one must first identify its owner." --Me
--Greg
 
Thanks for the code. When I run it, it fails on Line 2 saying "Object Required: Server". Please can you advise what I need to do to correct this?

Also, please can you advise how I get each field from the array as a variable (by that I mean for example, how do I get the Username from the text file and assign it to be strUser so I can use it in the script)?

Thanks in advance.

--------------------------------------------------------------------------
"Who is General Failure and what is he doing on my computer?"
--------------------------------------------------------------------------
 
>set fs=Server.CreateObject("Scripting.FileSystemObject")
Simply this---you're not running on a web server.
[tt]set fs=CreateObject("Scripting.FileSystemObject")[/tt]
 
how I get each field from the array as a variable
...
arrStr = Split(objTextFile.ReadLine,",")
strUser = arrStr(0)
strFullName = arrStr(1)
...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for all of your help guys, I have written my script and it is working great :)

--------------------------------------------------------------------------
"Who is General Failure and what is he doing on my computer?"
--------------------------------------------------------------------------
 
Sorry... everything I write runs on a web server. lol

Glad it's working for you.



Just my 2¢

"In order to start solving a problem, one must first identify its owner." --Me
--Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top