Solved

powershells cript to modify password for AD users from csv file

Posted on 2013-12-04
13
7,677 Views
Last Modified: 2013-12-11
hello,

i have windows 2008 r2 domain controller

i need a powershell script to modify an AD user password from csv file.

the csv are in this form:

user1,password
user2,password
....
where user1 is a samacountname.

if possible i need a log file to see if it sucess like this:

user1, password changed
user2,password changed
user3, password not changed (for exemple if not respect password policy)


thanks for help
0
Comment
Question by:cawasaki
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +2
13 Comments
 
LVL 19

Expert Comment

by:jss1199
ID: 39695939
I use Quest's (now Dell) AD cmdlets (freeware) - http://www.quest.com/powershell/activeroles-server.aspx

$changepass = Import-csv "C:\new_user_pass.csv"

foreach($line in $changepass) {set-QADUser $line.username -UserPassword $line.password } 

Open in new window

0
 
LVL 53

Assisted Solution

by:Will Szymkowski
Will Szymkowski earned 250 total points
ID: 39695994
You can accomplish this with built-in cmdlets from Active Directory. Use the below script below...

Import-Module activedirectory
$Resetpassword = Import-Csv "c:\PassChange.csv"
foreach ($Account in $Resetpassword) {
$Account.sAMAccountName
$Account.Password
Set-ADAccountPassword -Identity $Account.sAMAccountName -NewPassword (ConvertTo-SecureString $Account.Password -AsPlainText -force)
}

Open in new window


Create your CSV files with the following headings...

sAMAccountName    Password
jdoe                           P@ssword
etc...

Will.
0
 

Author Comment

by:cawasaki
ID: 39696006
@spec01

the file must be in this form: ???

sAMAccountName,Password
jdoe,password
steph,password
....

???

and for log file?
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 39696049
The sAMAccountName and Password are headings in the CSV file (column A would be sAMAccountName comlum B would be Password). There are no "," between the headings, they are heading for different columns. You then put the respective names/passwords under each heading.

As for the logging, if the password change fails you will get an error stating the name where it failed in the powershell window.

Will.
0
 

Author Comment

by:cawasaki
ID: 39696079
hi,

sorry i dont understand, in the csv file you put many space:

sAMAccountName    Password
jdoe                           P@ssword
etc...

may be it an excel file?
0
 
LVL 19

Expert Comment

by:jss1199
ID: 39696138
You may create the file in excel, the the two columns specified.  Simply save as type CSV
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 39696190
I put spaces in my post on here to illustrate the sepration between the columns. In Excel (saved as a CSV file) you have columns A B C D etc. Use the first 2 columns A and B and put in your headings as i have described above. Continue this pattern for the actual users and passwords under there respective headings.

Will.
0
 

Author Comment

by:cawasaki
ID: 39696219
Ok i will test.
Its possible to get a log file because if i lunsh the script for 100 account i cannot see all pn screen :)
Thanks for help
0
 
LVL 40

Accepted Solution

by:
footech earned 250 total points
ID: 39696450
I modified Spec01's script a bit to add the logging, and also added the -reset switch needed by Set-ADAccountPassword when not providing the old password.
Import-Module activedirectory
Import-Csv "PassChange.csv" | Foreach {
    $user = $_.sAMAccountName
    $pw = $_.Password
    try {
        Set-ADAccountPassword -Identity $user -NewPassword (ConvertTo-SecureString $pw -AsPlainText -force) -Reset
        Write-Output "$user,Success"
    } catch {
        Write-Output "$user,Error"
    }
} | Out-File PassChange.log

Open in new window

2
 
LVL 3

Expert Comment

by:Detlef001
ID: 39696484
0
 

Author Comment

by:cawasaki
ID: 39697921
hello,

so i have an excel file, i put a column to samaccountname and one for password, after that i need to save file to csv, but i have many csn file option like csv dos, csv macintosh...

wish one i choose?

thanks
0
 
LVL 40

Expert Comment

by:footech
ID: 39697948
Probably doesn't make a difference, but I wouldn't choose the Mac one.  Either ".CSV (Comma delimited)" or ".CSV (MS-DOS)" should work for you.
0
 

Author Closing Comment

by:cawasaki
ID: 39711563
thank you
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question