Mass change password from CSV, CSV contains username and individual passwords

I can see many similar questions asked but not quite what I'm looking for.
I work at a school and from our learning management software, we can export to CSV the Windows login names of the students and their birthdays. I need to be able to change their passwords to something based on their birthday because changing them to a generic password has caused chaos in the past. The little buggers don't need much time to mess with their mates. Anyway, so I'm chasing a script that can read a 2 column CSV. Column one being the username, column 2 being the password. The script needs to change the appropriate account to the password in column B then continue through the CSV and voila... all done!! Preferably the script wouldn't need an OU path etc.
Any help would be most appreciated.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


Not much time here so only got you a script which does need a OU part.

Not entily tested, but I hope this helps.

SET inputlist = FSO.OpenTextFile("input.txt", ForReading)
SET resultfile = FSO.OpenTextFile("log.txt", ForAppending, TRUE)
DO WHILE inputlist.AtEndOfStream <> TRUE
   strInputline = inputlist.Readline
   arrInput = split(strInputline, ",")
   strUserid = arrInput(0)
   strPassword = arrInput(1)
   Set objUser = GetObject _
   objUser.SetPassword strPassword

Open in new window

jeffb67Author Commented:
Thanks MorDrakka, I will have a play with this although I have seen it before. The reason I was wanting to get away from the OU structure in the script is that I have inherited this network and even though there are different OU's for the grades (and it's only one grade I need to change) I can't be sure that the kids are actually in the correct OU's. The export from the learning managent software is 100% accurate so a script that searches the whole AD for usernames will ensure only the correct students get their password changed. I will clean up AD, prolly using the same export from the LMS, but that's either another script or a bit of a big job which I don't quite have the time for just now.
You could also download adfind and admod from and do something like this:

for /f "tokens=1,2 delims=," %h in (users.txt) do adfind -default -f samaccountname=%h -dsq | admod #setpwd#::%i
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

jeffb67Author Commented:
Hey LauraEHunterMVP. I try and steer away from DOS commands where I can now, in an effort to force myself into Powershell. In any case VB is my prefered scripting for this type of thing. I have partly worked iit out by hacking up an old HTA script I've had for a while. Still... I continue to struggle :-(
I can provide a Powershell Script if your interested in that route.
Here is the Posh Code... it only took a second so I did anyway :)

This assumes you have a header row on the CSV with username,Password

MAN, I love Powershell.
foreach($user in (import-Csv C:\YourCSVFile.csv))
    Write-Host "Setting Password for $($User.username)"
    $ds = new-Object System.DirectoryServices.DirectorySearcher([ADSI]"","(&(objectcategory=user)(sAMAccountName=$($user.username)))")
    $usr = ($ds.Findone()).GetDirectoryEntry()

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jeffb67Author Commented:
The syntax in PS scares me a bit but given the size of the script compared to the VB equivalent, it's pretty impressive. Looks like it's back to school for me on PS. Thanks again... you're a life saver.
I understand that learning new things can be daunting.. if you have any questions please let me know.
When using the above powershell script I receive the following error:

Setting Password for CN=jsmith
You cannot call a method on a null-valued expression.
At :line:5 char:44
+     $usr = ($ds.Findone()).GetDirectoryEntry <<<< ()

The CSV File I am referencing is as follows:

I tested this and it worked great.  Thanks for the good work.  
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.