Clear Manager info for all users in an OU

PaulRKrueger
PaulRKrueger used Ask the Experts™
on
We have an OU where we put disabled users. I need a script that, when run, will clear out the entry in the "manager" filed for each user object in the OU.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Sr. Analyst - System Administrator
Commented:
Modified the script from the link below:
http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/usersgroups/users/

On Error Resume Next
Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D
Const ADS_PROPERTY_CLEAR = 1 
Set objUser = GetObject _
   ("LDAP://ou=Management,dc=NA,dc=fabrikam,dc=com") 
objUser.PutEx ADS_PROPERTY_CLEAR, 
objUser.SetInfo
 
arrDirectReports = objUser.GetEx("directReports")
If err.number = E_ADS_PROPERTY_NOT_FOUND Then
    WScript.Quit
Else
    For Each strValue in arrDirectReports
        Set objUserSource = GetObject("LDAP://" & strValue)
        objUserSource.PutEx ADS_PROPERTY_CLEAR, "manager", 0
        objUserSource.SetInfo
    Next
End If

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial