Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove 1200 accounts from a group

Status
Not open for further replies.

coch

Technical User
Jul 4, 2002
106
0
0
GB
I Have a DG with thousands of users in there, I would like to run a script that checks the membership of the group and if an account is hidden from the GAL to remove it from the group and output a list of the accounts that is has removed. Getting a little confused with IADS & PutEx as I can only do it by passing a DN of an individual. I need the script to basically search on (memberOf=CN=All People,OU=Exchange Recipients,DC=domain,DC=com)(&(&(objectclass=user)(msExchHideFromAddressLists=TRUE)))) and remove them.
Any ideas
 
If you are getting confused with it I would suggest you break this out into a few steps.

1. Export a list of the Groups Members.
2. Check each member for the hidden attribute. If not hidden add to an array.
3. Write the contents of the array to a file.
4. Delete all group members.
5. Write the new member list using your file as input.

I hope you find this post helpful.

Regards,

Mark
 
thanks Mark,
Is there not a way to do what I want without removing all and adding back in?
 
Yes there is, but as you said you were getting confused, I think you will find this method to be the easiest and fastest for you. You can do it all in multiple steps without affecting the group until you are ready to apply the new member list.

I hope you find this post helpful.

Regards,

Mark
 
thanks Mark, Persevered and with a bit of help from another site came up with this below which worked great

Option Explicit

Dim objContainer
Dim objGroup
Dim objUser
Dim objExUser
Dim strFile
Dim objFSO
Dim objFile
Const ForAppending = 8
strFile = "Removed.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile = objFSO.OpenTextFile(strFile,ForAppending, True)

Set objContainer = GetObject("LDAP://OU=Accounts,dc=domain,dc=co,dc=uk")
Set objGroup = objContainer.GetObject("group","CN=all staff")

objContainer.Filter = Array("user")
For Each objUser in objContainer
Set objExUser = GetObject(objUser.adspath)
If objExUser.msExchHideFromAddressLists=TRUE Then
objFile.WriteLine "Removing: "& objUser.Name
Call objGroup.Remove(objUser.AdsPath)
End If
Next
objFile.Close
Wscript.Echo "Finished"
 
Nice job.

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top