troubleshooting Question

Search for a group in AD

Avatar of bpl5000
bpl5000 asked on
VB Script
7 Comments1 Solution273 ViewsLast Modified:
Is there a way to search for a group using vb script?  I want to search for a group, and if it exists, return the location.  Anyway to do this?  I have code to list the members of a group, but right now I have it pointing to the Accounting OU.  I need to first search for the group, then grab the members if the group does exist.  Any help would be appreciated!
   
Dim arrNames()
intSize = 0

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("members.txt", True)

strInput = UserInput( "Enter Group Name:" )

On Error Resume Next

Set objGroup = GetObject("LDAP://CN=" & strInput & ",OU=Accouting,OU=abc_Users,DC=abc,DC=local")

For Each strUser in objGroup.Member
    Set objUser =  GetObject("LDAP://" & strUser)
    ReDim Preserve arrNames(intSize)
    arrNames(intSize) = objUser.CN
    intSize = intSize + 1
Next

For i = (UBound(arrNames) - 1) to 0 Step -1
    For j= 0 to i
        If UCase(arrNames(j)) > UCase(arrNames(j+1)) Then
            strHolder = arrNames(j+1)
            arrNames(j+1) = arrNames(j)
            arrNames(j) = strHolder
        End If
    Next
Next 

For Each strName in arrNames
     objFile.WriteLine strName
Next

Wscript.Echo "Output Complete"

Function UserInput( myPrompt )
    ' Check if the script runs in CSCRIPT.EXE
    If UCase( Right( WScript.FullName, 12 ) ) = "\CSCRIPT.EXE" Then
        ' If so, use StdIn and StdOut
        WScript.StdOut.Write myPrompt & " "
        UserInput = WScript.StdIn.ReadLine
    Else
        ' If not, use InputBox( )
        UserInput = InputBox( myPrompt )
    End If
End Function
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros