troubleshooting Question

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

Avatar of amendala
amendala asked on
Active DirectoryMicrosoft Legacy OSWindows Server 2008
2 Comments1 Solution1128 ViewsLast Modified:
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!
ASKER CERTIFIED SOLUTION
X_layer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros