Directory Services |
[This documentation is preliminary and subject to change.]
To remove an ADAM user object from an ADAM group object, bind to the group and the user, and use the Remove method on the group.
You can add the object you remove with the following code example by Adding an ADAM User to an ADAM Group.
The following VBScript code example uses the GetObject function to bind to an organization object, uses the GetObject function to bind to an group object in a organizationalUnit object of the organization and a user object in the organization, and uses the Remove method to remove the user from the group.
' Remove ADAM User from ADAM Group. Option Explicit Dim objADAM ' Binding object. Dim objGroup ' Group object. Dim objUser ' User object. Dim strGroup ' Group. Dim strPath ' Binding path. Dim strOU ' Organizational unit. Dim strUser ' User. ' Construct ADAMsPath binding string. ' Change "localhost" to appropriate server. ' Change "389" to port for appropriate instance. ' Change "O=Fabrikam,C=US" to appropriate object. strPath = "LDAP://localhost:389/O=Fabrikam,C=US" WScript.Echo "Bind to: " & strPath ' Specify User. strUser = "TestUser" ' Specify Group. strGroup = "TestGroup" ' Specify Organizational Unit. strOU = "TestOU" WScript.Echo "Remove: " & strUser WScript.Echo " from" WScript.Echo " " & strGroup On Error Resume Next ' Bind to the root. Set objADAM = GetObject(strPath) ' Output error if the bind operation fails. If Err.Number <> vbEmpty Then WScript.Echo "Error: Bind failed." WScript.Quit End If ' Remove User from Group. Set objGroup = objADAM.GetObject("group", "CN=" & strGroup & _ ",OU=" & strOU) Set objUser = objADAM.GetObject("user", "CN=" & strUser) objGroup.Remove objUser.AdsPath ' Output success or error. If Err.Number <> vbEmpty Then WScript.Echo "Error: Remove failed." Else WScript.Echo "Success: User removed from group." End If