Hi,
I have a below script to remove the users from the specific group from AD:
DIM objGroup, objRootLDAP, objFSO, objInput, objConnection, objCommand
DIM strUser
On Error Resume Next
Set objRootLDAP = GetObject("LDAP://rootDSE")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInput = objFSO.OpenTextFile("users.txt") -----I have entered the user ID(12345) and saved it on desktop as a txt file.(hardcoded).
Set objGroup = GetObject("LDAP://cn=groupname-SD-Animal,ou=OU,dc=DOMAIN,dc=COM") --group name as abcd test_group(hardcoded)
Do Until objInput.AtEndOfStream
strUser = ObjInput.ReadLine
objCommand.CommandText = "<LDAP://dc=DOMAIN,dc=COM>;(&(objectCategory=person)(sAMAccountName=" & strUser & "));distinguishedName,userAccountControl;subtree"
Set objRecordSet = objCommand.Execute
If objRecordSet.RecordCount = 0 Then
MsgBox strUser & " was not found!" & VbCrLf & "Skipping", VbOkOnly,"User Not Found"
Else
strDN = objRecordSet.Fields("distinguishedName")
Set objUser = GetObject("LDAP://" & strDN)
objGroup.Remove(objUser.AdsPath)
End If
Loop
WScript.Echo "Complete"
When I tried to run the script it shows the user not found, Actually user was found in AD eventhough it is displaying as user not found.Kindly help me out where I have missed.
Thanks
Raj