Solved

Powershell reset password and enable-adaccount not working

Posted on 2014-12-19
5
203 Views
Last Modified: 2014-12-19
I have some users in an OU and have been using this command to try and reset their passwords (with a variable $pwd) and then enable their accounts. I get no errors in powershell but the accounts do not become enabled.?

Get-ADUser –Filter  ‘enabled –eq “false”’ –SearchBase “OU=students,OU=science,OU=domain,DC=domain,dc=local” | Set-ADAccountPassword  -NewPassword $pwd  –reset –PassThru | enable-adaccount

Where can I look in Event Viewer for errors.?

thanks in advance

mat
0
Comment
Question by:matedwards
[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
  • 3
  • 2
5 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 40508904
Try..
Get-ADUser –Filter  ‘enabled –eq “false”’ –SearchBase “OU=students,OU=science,OU=domain,DC=domain,dc=local” | %{$_ | Set-ADAccountPassword  -NewPassword $pwd  –reset;$_ | Enable-ADAccount}

Open in new window

0
 

Author Closing Comment

by:matedwards
ID: 40509163
Fantastic Subsun.. worked a treat..

Can you explain what you did..? I'm a bit of a power shell novice..

Many thanks

Mat
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40509181
Ideally your command should work as  –PassThru switch will allow Set-ADAccountPassword command to pass the user object to pipeline, so the Enable-ADAccount can process it. For some reason it was not working for you.. So I just ran the commands individually with the help of ForEach-Object loop.. More elaborated version of same command is shown below.. Hope it's gives you a clear picture..

Get-ADUser –Filter  ‘enabled –eq “false”’ –SearchBase “OU=students,OU=science,OU=domain,DC=domain,dc=local” | ForEach-Object {

$_ | Set-ADAccountPassword  -NewPassword $pwd  –reset

$_ | Enable-ADAccount

}

Open in new window


I have written a couple of articles for explain the basics. Please Check it out and see if it helps.. :-)

http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/A_12536-Active-Directory-module-PowerShell-cmdlets-Part-1.html

http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/A_12657-Active-Directory-module-PowerShell-cmdlets-Part-2.html
0
 

Author Comment

by:matedwards
ID: 40509229
Certainly will.. many thanks again

Mat
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40509244
You're welcome!!
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

I had a question today where the user wanted to know how to delete an SSL Certificate, so I thought that I would quickly add this How to! Article for your reference. WHY WOULD YOU WANT TO DELETE A CERTIFICATE? 1. If an incorrect certificate was …
A procedure for exporting installed hotfix details of remote computers using powershell
This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…

752 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