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

asked on

Find all disabled users direct reportees and remove them.

Hi,

I want a way to find all disabled users if they have direct reporters and remove them from the managers stste.

I have this that displays the users with direct reportees names.

DSQuery * -Filter "(&(objectCategory=user)(samAccountName=*)(directReports=*)(userAccountControl:1.2.840.113556.1.4.803:=2))" >C:\DisabledUsersWithDirectReports.

Can this be edited to remove them.,

Regards
Sharath
Avatar of ll_jaxn
ll_jaxn

use the filesystemobject to read the file one line at a time and execute the delete

Or instead of doing a Query, to a delete with the same fileter
Hi Sharath,
Check following script if this works for you.

::  *** SCRIPT START  ***
@ECHO OFF
IF EXIST RemoveMgr.ldf DEL /F /Q RemoveMgr.ldf
DSQuery * -Filter "(&(sAMAccountType=805306368)(userAccountControl:1.2.840.113556.1.4.803:=2)(directReports=*))" -Attr directReports -L -Limit 0 >RemoveMgr.txt
FOR /F "delims=*" %%u IN ('TYPE RemoveMgr.txt') DO (
    ECHO Processing: %%u
      (      ECHO DN: %%u
            ECHO changetype: modify
            ECHO delete: Manager
            ECHO -
            ECHO.)>>RemoveMgr.ldf)
IF EXIST RemoveMgr.ldf LDIFDE -I -K -F RemoveMgr.ldf
IF EXIST RemoveMgr.ldf DEL /F /Q RemoveMgr.ldf
IF EXIST RemoveMgr.txt DEL /F /Q RemoveMgr.txt
EXIT /B 0
:: *** SCRIPT END ***
Avatar of bsharath

ASKER

Farhan i think it works fine..But after it removes can i get a results file.On what has been removed...
Its working fine.It has removed all users who have managers that are disabled...Thanks...If a report at the end is possible it would be great
What report should include?
What all it has removed from direct reportees
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
Thanks Farhan....