Flight5497
asked on
Script to remove multiple users from a secutiry group
Hi Experts,
I have a script at the moment that adds multiple users in to a particular security group, I was wondering if there was a way to do the same but in reverse, and thus removing multiple active directory users from a security group?
I have included a snippet of the code we use to add multiple users to a security group for your reference, to see what we do and how we do it.
Kindest Regards
I have a script at the moment that adds multiple users in to a particular security group, I was wondering if there was a way to do the same but in reverse, and thus removing multiple active directory users from a security group?
I have included a snippet of the code we use to add multiple users to a security group for your reference, to see what we do and how we do it.
Kindest Regards
Option Explicit
Dim objRootLDAP, objGroup, objUser, objOU
Dim strOU, strOU2, strGroup, strDNSDomain
Dim intCounter
strOU = "OU=Users,OU=01-Bournemouth,OU=Stores,OU=Beales Users,"
strOU2 = "OU=Security Groups,OU=Beales Groups,"
strGroup = "CN=Remote Users,"
Set objRootLDAP = GetObject("LDAP://RootDSE")
strDNSDomain = objRootLDAP.Get("DefaultNamingContext")
Set objGroup = GetObject("LDAP://"& strGroup _
& strOU2 & strDNSDomain)
Set objOU =GetObject("LDAP://" & strOU & strDNSDomain)
intCounter = 1
For Each objUser In objOU
If objUser.Class = lcase("User") then
objGroup.add(objUser.ADsPath)
intCounter = intcounter +1
End If
Next
WScript.Echo strGroup & " has " & intCounter & " new members"
Wscript.Quit
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ah that is brilliant mate, thank you very much it was that simple :P now I feel suitably silly :)
I would also like to ask while I am here another problem I had with the above script just a second ago is that when I tell it to add all users in the OU to a group and it finds a user that is already in the group it falls over and does not carry on with the users that are not in the group.
Is there someway of amending it to allow for this?
I would also like to ask while I am here another problem I had with the above script just a second ago is that when I tell it to add all users in the OU to a group and it finds a user that is already in the group it falls over and does not carry on with the users that are not in the group.
Is there someway of amending it to allow for this?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you're interested, please let me knwo. I will prepare a syntax for you :)
Regards,
Krzysztof