I need to dump the names of all groups in my AD that have no members into a TXT file. I have looked for a few days now, certain that somebody had already done this, but no joy on the plagurism attempt. Close, but not what I'm looking for. Here's something close:
This code is SUPPOSED to list groups with 1 or 0 members. But it lists all groups, claiming they all have one member. That's not what I'm looking for anyhow.
I thought I saw once where sombody used some NOT (!Members=*) qualifier on the query command, but the following does not work for me.
this returns 80040e14 error from provder at the 'Set objRecordSet = objCommand.Execute' line.
Any syntax hints, or completely different ides to get the same place will be welcomed.
Thanks,
David J.
Code:
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = "SELECT ADsPath, Name FROM 'LDAP://dc=thadmin,dc=com' WHERE objectCategory='group'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Set objGroup = GetObject(objRecordSet.Fields("ADsPath").Value)
i = 0
For Each strUser in objGroup.Member
i = i + 1
If i > 1 Then
Exit For
End If
Next
If i <= 1 Then
Wscript.Echo objRecordSet.Fields("Name").Value & " -- " & i
End If
objRecordSet.MoveNext
Loop
I thought I saw once where sombody used some NOT (!Members=*) qualifier on the query command, but the following does not work for me.
Code:
'On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = "SELECT ADsPath, Name FROM 'LDAP://dc=thadmin,dc=com' WHERE (objectCategory='group')(!members=*)"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo objRecordSet.Fields("Name").Value
objRecordSet.MoveNext
Loop
Any syntax hints, or completely different ides to get the same place will be welcomed.
Thanks,
David J.