Disable and enable all users in a OU.

Posted on 2007-09-30
Last Modified: 2008-05-31

I want a script with which i can disable all users in a OU .And a way to enable the same when required.

Is there a way to do this.


Question by:bsharath
    LVL 70

    Expert Comment

    dsquery user ou=NameOfOU,dc=Mydomain,dc=org -limit 0 | dsmod user -disabled yes

    and to enable them

    dsquery user ou=NameOfOU,dc=Mydomain,dc=org -limit 0 | dsmod user -disabled no
    LVL 23

    Expert Comment

    by:Malli Boppe
    I am not sure if this works.Can you highlight all the users at once and right click to see if you get the option to disbable the users.
    LVL 11

    Author Comment

    I get this.

    C:\>dsquery user OU=CMS,OU=External Users,OU=User Accounts,OU=Countries,D
    C=Development,DC=Group,DC=co -limit 0 | dsmod user -disabled yes
    dsquery failed:`Users,OU=User' is an unknown parameter.
    type dsquery /? for help.dsmod failed:`Target object for this command' is missin
    type dsmod /? for help.
    LVL 26

    Expert Comment

    Try this:

    DSQuery user "Distinguished Name" -name * -Limit 0 |DSMod user -disabled no/yes

    (To disable)
    DSQuery user "OU=SALES,DC=TRAINING,DC=COM" -name * -Limit 0 |DSMod user -disabled yes

    (To enable)
    DSQuery user "OU=SALES,DC=TRAINING,DC=COM" -name * -Limit 0 |DSMod user -disabled no
    LVL 26

    Accepted Solution


    DSQuery user "Distinguished Name" -name * -Limit 0 |DSMod user -disabled no/yes
                                          ^-----OU Distinguished Name                                                      

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
    Mapping Drives using Group policy preferences Are you still using old scripts to map your network drives if so this article will show you how to get away for old scripts and move toward Group Policy Preference for mapping them. First things f…
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now