Solved

2003 - AD User & Computers Find Groups

Posted on 2011-03-17
3
298 Views
Last Modified: 2013-11-05
Have a requirement within a large 2003 Domain where I need to search for long named groups from as little as a x3 letter description e.g xyz.  I understand how to use advanced find using end or start words but, there is nothing that works within an advanced search that allow for the scario where you need to find "xyz" within the group string. Does anyone know of a script that will do this ?
0
Comment
Question by:kgeddes
3 Comments
 

Expert Comment

by:celborn
ID: 35159923
I recommend using MMC (via active directory addin) especially if you manage more than one active directory domain
0
 

Author Comment

by:kgeddes
ID: 35160021
Sorry but, MMC is not an option in our environment. I was looking for a script.
0
 
LVL 31

Accepted Solution

by:
Justin Owens earned 500 total points
ID: 35160153
This other Question:

http:/Q_21407686.html

has the following 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 FROM 'LDAP://dc=domain,dc=com' WHERE objectCategory='group' "
   
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    Set objType = GetObject(objRecordSet.Fields("ADsPath").Value)
        If objType.GroupType > 0  Then
            Wscript.Echo "Group: " & objType.cn
        End If
    objRecordSet.MoveNext
Loop

Open in new window

with the disclaimer "If you make the GroupType < 0 then it will display only security groups."

In theory, you should be able to add a AND ... LIKE statement to that, like this:
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 FROM 'LDAP://dc=domain,dc=com' WHERE objectCategory='group' AND samAccountName LIKE '%xyz%' "
   
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    Set objType = GetObject(objRecordSet.Fields("ADsPath").Value)
        If objType.GroupType < 0  Then
            Wscript.Echo "Group: " & objType.cn
        End If
    objRecordSet.MoveNext
Loop

Open in new window

samAccountName may need to be samAcctName.  I am not at my lab to test.

DrUltima
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Batuhan Cetin In this article I will be guiding through the process of removing a failed DC metadata from Active Directory (hereafter, AD) using the ntdsutil tool in a Windows Server 2003 environment. These steps are not necessary in a Win…
This may not be a text book method to resolve VSS backup issues but it seemed to have worked on few of the Windows 2003 servers we had issues while performing a Volume Shadow Copy backup. If you have issues while performing a shadow copy backup usin…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now