?
Solved

Remove user from groups with Admodify

Posted on 2007-07-30
3
Medium Priority
?
1,008 Views
Last Modified: 2008-05-31
Is there a way with Admodify to remove a group of users from all groups excluding domain user in bulk?
There is no consistency with what users are associated to what groups for reference
0
Comment
Question by:GRV001
2 Comments
 
LVL 30

Accepted Solution

by:
LauraEHunterMVP earned 1000 total points
ID: 19601645
The reason this is trickier than you think is because group memberships are not stored as a property of the -user-, but of the -group-.  So to remove a user from every group that it is a member of, you need to:

[1] Enumerate the user's current group memberships
[2] Connect to each group that the user is a member of
[3] Delete the user from that group's 'member' attribute

As you can see, you need to modify each group in turn, it's not actually a function of modifying the user object.

Something like the following VBScript will accomplish what you're looking for on a single user object:

Const ADS_PROPERTY_DELETE = 4
Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D
 
Set objUser = GetObject("LDAP://<UserDN>")
arrMemberOf = objUser.GetEx("memberOf")
 
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
    WScript.Echo "No group memberships found."
    WScript.Quit
End If
 
For Each Group in arrMemberOf
    Set objGroup = GetObject("LDAP://" & Group)
    objGroup.PutEx ADS_PROPERTY_DELETE, _
        "member", Array("<UserDN>")
    objGroup.SetInfo
Next

Hope this helps.

Laura E. Hunter - Microsoft MVP: Windows Server - Networking
0
 
LVL 1

Expert Comment

by:Computer101
ID: 21447523
Forced accept.

Computer101
EE Admin
0

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn't it be nice if objects in Active Directory automatically moved into the correct Organizational Units? This is what AutoAD aims to do and as a plus, it automatically creates Sites, Subnets, and Organizational Units.
It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

864 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