Solved

Powershell reset password and enable-adaccount not working

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

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

Question has a verified solution.

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

If you migrate a Terminal Server licenses server inside the 2008 server family, you can takte advantage of the build-in migration tool. If you like to migrate an older 2003 Server (and the installed client CALs) to a 2008 R2 server for example, you …
A safe way to clean winsxs folder from your windows server 2008 R2 editions
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…
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 …

679 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