We help IT Professionals succeed at work.
Get Started

Need a Powershell script to go through an OU and all Sub-OUs disabling any user accounts NOT ALREADY DISABLED.

1,127 Views
Last Modified: 2012-04-27
Folks -

I need help crafting a Powershell script to filter through an OU and all Sub-OUs inspecting user accounts.  The goal is to end up with all the accounts in the parent OU and below being disabled.  However, I only want to modify the account if it is currently enabled.  In other words, to keep my audit logs clean, I don't want to run through setting the UserAccountControl flag for every single account to Disabled.  That clutters my logs with thousands and thousands of "User Account Management" events.  I only want to change accounts that are currently enabled.

Hopefully this makes sense.  The script should target a given OU, all the user accounts in it and in Sub OUs, and should disable only accounts that are currently enabled.  Placing the DN of the top-most OU in the code is just fine, it doesn't need to accept parameters off the command line.

Thanks!
Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE