Solved

Powershell reset password and enable-adaccount not working

Posted on 2014-12-19
5
163 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
  • 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Recently, I was asked to look into SCCM 2007 by my employer, having a degree of experience of earlier versions of SMS and some previous SCCM knowledge I didn't expect the procedure to involve to much time. I read a number of guides concerning it…
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now