We help IT Professionals succeed at work.

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.
Watch Question


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


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 www.joeware.net/freetools 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


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


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.