Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

powershells cript to modify password for AD users from csv file

Posted on 2013-12-04
13
Medium Priority
?
8,444 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 1000 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 41

Accepted Solution

by:
footech earned 1000 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 41

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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

719 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