Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Disable and enable all users in a OU.

Hi,

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.

Regards
Sharath

Avatar of Brian Pierce
Brian Pierce
Flag of United Kingdom of Great Britain and Northern Ireland image

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
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.
Avatar of bsharath

ASKER

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
g.
type dsmod /? for help.
Try this:

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

Like:
(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
ASKER CERTIFIED SOLUTION
Avatar of Farhan Kazi
Farhan Kazi
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial