Search AD Containers and OUs

I need a script that can search of user groups that have no memberships.
The search can be done not only on the OU but also on the AD containers that are not an OU.

Thanks
jskfanAsked:
Who is Participating?
 
jskfanAuthor Commented:
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 Name,Member FROM 'LDAP://dc=rustice,dc=local' WHERE objectCategory='group'"
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    If isNull(objRecordSet.Fields("Member").Value) Then
          Wscript.Echo objRecordSet.Fields("Name").Value
    End If
    objRecordSet.MoveNext
Loop
0
 
jskfanAuthor Commented:
That's rich of info.

Could you please just paste here the script that can get the result I am looking for?

thanks
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
JamesSenior Cloud Infrastructure EngineerCommented:
This link here that I have provided should do the trick and it will output the information in a excel sheet. There is an explaination of what the script does, so make sure to read this.

http://gallery.technet.microsoft.com/scriptcenter/d5c6b119-0337-4b5d-93f3-c409c6cf7a45

0
 
Mike KlineCommented:
Take a look at this question I helped with

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24719704.html

I used adfind for my method (much less typing) there are also vbscript examples there too.

Thanks

Mike
0
 
jskfanAuthor Commented:
it sounds like I will have to scroll all over the spreadsheet and see which group doesn't have an x , to tell if it's empty.
I got a script few days ago that worked 95% for me. Why 95 %? because
 -a it retrieved some user groups that have members in them
- b it works only for OUs , if I run the script agains a container which is not an OU, it doesn't get anything or it throws an error.

0
 
jskfanAuthor Commented:
it was still a very helpful script...

I need similar script but that can run also against the AD containers that are not OUs.
0
 
jskfanAuthor Commented:
All I needed was to replace OU with CN ....

0
 
jskfanAuthor Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.