Solved

powershells cript to modify password for AD users from csv file

Posted on 2013-12-04
13
7,101 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
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

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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