Solved

Powershell reset password and enable-adaccount not working

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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 …
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

773 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