Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

Powershell reset password and enable-adaccount not working

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
matedwards
Asked:
matedwards
  • 3
  • 2
1 Solution
 
SubsunCommented:
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
 
matedwardsAuthor Commented:
Fantastic Subsun.. worked a treat..

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

Many thanks

Mat
0
 
SubsunCommented:
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
 
matedwardsAuthor Commented:
Certainly will.. many thanks again

Mat
0
 
SubsunCommented:
You're welcome!!
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now