Solved

2003 - AD User & Computers Find Groups

Posted on 2011-03-17
3
296 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:
DrUltima 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The HP utility "HP Lights-Out Online Configuration Utility for Windows Server 2003/2008" could be of great use when it comes to remotely configure a HP servers ILO WITHOUT rebooting the server. We would only need to create and run scripts using thi…
Numerous times I have been asked this questions that what is it that makes my machine log on so slow, there have been cases where computers took 23 minute exactly after taking password and getting to the desktop. Interesting thing was the fact th…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 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

22 Experts available now in Live!

Get 1:1 Help Now