Jump to content

assign variables from a text file line by line?


Recommended Posts

I did a quick search for this and did not find exactly what I was looking for, so hopefully you all can help me. I am using waters script to create AD accounts with a simple gui, but the need to mass create accounts is needed. We have a user that needs about 30 accounts created. So I am going to modify my script to create user accounts based on lines in a text file. But to do these I want to have each line be a different field. soo for example.

FirstName

LastName

Email

Phone

Email Address

Manager

FirstName2

LastName2

Email2

Phone2

Email Address2

Manager2

So i was curious if there was an easy way to assign a line to an array, and automatically go to the next line when the function is called, or something similar to this.

Thanks!

Link to comment
Share on other sites

I suppose

You can either loop through the file, or loop through the array, in both cases you are going to have to parse it.

Well the filereadline is nice. I can do

$line = FileReadLine($file)
$last = $line

$line = FileReadLine($file)
$email = $line

$line = FileReadLine($file)
$phone = $line

and it makes it easier. The downside is that everytime the function is called it has to search through the entire document, but luckily for my needs this is plenty fine, and nice so I can be lazy.

One issue I ran into, I am trying to generate a password to automatically set these created accounts to using a simple formula. One thing I want to put is their last 4 digits of their phone number in, but to be completely honest I dont know how to change these to arrays. So after I get to...

$line = FileReadLine($file)
$phone = $line

I cant simply do something like

$size = Ubound($phone)
$lowerlimit = $size - 3
$i = 0
While $lowerlimit <= $size
$NewArry[i] = $phone[$lowerlimit]
$i = $i + 1
$lowerlimit = $lowerlimit + 1
WEnd

...Please bear with this, I just wrote it down real quick... I guess a for loop would be a lot better, but you get the idea :mellow:

But unfortunately Ubound($phone) returns 0 because its not an array, any ideas how I can get this text to be indexed?

*EDIT*

I solved this using StringRight, did exactly what I needed too, but stringsplit would have also worked fine.

Edited by ICANSEEYOU7687
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...