Solved

Need a VB Script to List all Groups and the OU they are in

Posted on 2004-10-18
5
866 Views
Last Modified: 2012-06-27
Hi,

I want to write a VBS script to get a listing of all Groups in the domain along with the OU that they belong to.

I know how to get the Group.Name, how can I a get a listing of all the information that would be available under that object?

Thanks
0
Comment
Question by:praflik
  • 2
5 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 250 total points
ID: 12342711
Here you go.  The VBScript below will loop through all the OUs in the path specified and print out the names of the groups and the OU they were found in.  All you need to do is edit the first line and put in your LDAP path.  The script echos the information out so unless you want to have to keep hitting Return I suggest you run it with Cscript instead of Wscript.


---- BEGIN SCRIPT ----
ProcessOU "LDAP://server.company.com/dc=company,dc=com"
Wscript.Quit

Private Sub ProcessOU(strADSPath)
    Dim objAD
    Dim objOU
    Set objAD = GetObject(strADSPath)
    objAD.Filter = Array("OrganizationalUnit")
    SearchForGroups objAD.ADsPath, objAD.Name
    For Each objOU In objAD
        ProcessOU objOU.ADsPath
    Next
End Sub

Private Sub SearchForGroups(strADSPath, strOUName)
    Dim objOU
    Dim objGroup
    Set objOU = GetObject(strADSPath)
    objOU.Filter = Array("group")
    For Each objGroup In objOU
      Wscript.Echo "Group=" & Mid(objGroup.Name,4) & Space(50 - Len(Mid(objGroup.Name,4))) & strOUName
    Next
End Sub
0
 
LVL 76

Expert Comment

by:David Lee
ID: 12561214
Accept BlueDevilFan http:#12342711
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

773 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