I'm trying to dynamically remove and add users to a group on a domain using a
login script but I get an access denied error on
objGroup.Remove objUser.AdsPath
Does anyone know why and how to resolve it?
wscript.echo "Test Script."
' Remove AD LDS User from AD LDS Group.
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 the binding string.
strPath = "ldap path"
WScript.Echo "Bind to: " & strPath
' Specify User.
strUser = "CN..."
' Specify Group.
strGroup = "CN..."
WScript.Echo "Remove: " & strUser
WScript.Echo " from"
WScript.Echo " " & strGroup
' Bind to root.
Set objADAM = GetObject(strPath)
' Output error if bind fails.
If Err.Number <> vbEmpty Then
WScript.Echo "Error: Bind failed."
WScript.Quit
End If
' Remove User from Group.
Set objGroup = objADAM.GetObject("group", strGroup)
Set objUser = objADAM.GetObject("user", strUser)
objGroup.Remove objUser.AdsPath
' Output success or error.
If Err.Number <> vbEmpty Then
WScript.Echo "Error: Remove failed."
WScript.Echo Err.Description
Else
WScript.Echo "Success: User removed from group."
End If