Shortcut Menu

Skip

Main Navigation

Choose your language

You are here:

ActiveXperts.com > Administration > Scripts > Adsi > Remove All Group Memberships for a User Account

ActiveXperts Network Monitor

Quicklinks


NOTE: ActiveXperts Network Monitor supports SNMP based checks. It ships with free SNMP GET and SNMP TRAP utilities. It also offers many SNMP scripts (PowerShell and VBScript). Download Now »


Remove All Group Memberships for a User Account - VBScript sample

You can use any of the VBScript programs below in ActiveXperts Network Monitor. Click here for an explanation about how to include scripts in ActiveXperts Network Monitor.


Description

Removes the MyerKen user account from all Active Directory security groups.

Example(s)

On Error Resume Next

Const ADS_PROPERTY_DELETE = 4
Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D
 
Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com") 
arrMemberOf = objUser.GetEx("memberOf")
 
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
    WScript.Echo "This account is not a member of any security groups."
    WScript.Quit
End If
 
For Each Group in arrMemberOf
    Set objGroup = GetObject("LDAP://" & Group) 
    objGroup.PutEx ADS_PROPERTY_DELETE, _
        "member", Array("cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
    objGroup.SetInfo
Next