Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

December 28, 2009 12:00 AM

Document Your Domain Groups

The final report will please you, your security department, and your auditors
Windows IT Pro
InstantDoc ID #103358
Rating: (10)
Downloads
103358.zip

Let me start by saying that this isn't your typical group-listing script. This admin script produces a very thorough single-domain listing of all your Active Directory (AD) groups in a nicely formatted, easy-to-read layout. The report it produces provides you with an excellent point-in-time group history document and supplies a great deal of information to you, your security department, and your auditors.

Here's a list of the script's major features:

  • enumerates all domain groups within a single domain
  • lists and enumerates all nested groups
  • presents information in one Excel document with each group on its own worksheet
  • lists users whose primary group is the group being enumerated (these members don't normally show up in group listings unless you take care to account for this situation as this script does; for example, if you as a domain admin set your primary group to Domain Admins and do a simple group listing of that group, you won't see yourself as a member in that listing)
  • colors nested group names in red and recurring groups in purple
  • avoids possible endless loops should one group contain another group that contains the first group
  • sorts and indents by group
  • provides a domain group summary list with hyperlinks to all groups that have members
  • provides a no members summary list if there are any groups without members, including hyperlinks to the groups
  • colors worksheet tabs in red for easy identification of groups with no members
  • uses blue text for disabled user accounts within groups
  • provides total group counts for both groups with and without members

Script Overview

The script cycles through a collection of groups within a single AD domain and writes each group's members and nested group members into its own specific Excel worksheet. (You can download the script by clicking the Download the Code Here button.) In the end, all the individual domain group worksheets make up the overall domain group listing spreadsheet. In addition to the individual group worksheets, a summary worksheet is created and, if any groups have no members, an additional worksheet is created listing all the groups that have no members.

During the process of evaluating individual groups, disabled accounts are highlighted in blue; any nested groups are indented and highlighted in red and members of those nested groups are also indented and listed under their specific parent group.

If a specific nested group happens to occur more than once in any specific listing, it's not enumerated again but rather highlighted in purple; you'll find that the fully enumerated group already exists elsewhere within that group listing. A summary worksheet is created at the end of the process, providing group total information and easy-to-use hyperlinks to all your groups for quick and easy analysis.

If your domain has any groups that do not contain members, a separate groups with no members worksheet is created, providing the names and hyperlinks to those groups that have no members. The resulting spreadsheet with its color coding and nested group indentation scheme provides a very thorough and easy-to-comprehend picture of your domain's group infrastructure.

How It Works

Aside from setting up some variables, constants, and an instance of Excel, the first process the script undertakes is to create a dictionary that contains a list of all disabled accounts. This is done by querying AD. The dictionary is used at a couple of key points within the script while enumerating group member users to determine if the user account is disabled or not. You'll see this later on in the script. If an account is disabled, that userid is formatted in the Excel output with a blue font, making it easy to spot within the group listings.

Next, a collection of all domain groups is gathered using the simple AD query shown in Listing 1. Stepping though the group collection constitutes the main loop of the script, where all groups are ultimately enumerated. Within this main loop a call is made to the GetGroupMembers subroutine, which is really the workhorse of this whole process. It's within the GetGroupMembers subroutine that each group's membership is individually evaluated and written to the Excel report.

Related Content:

ARTICLE TOOLS

Comments
  • Wallace
    2 years ago
    Oct 15, 2010

    Also , it would be great to link this to Visio and have some kind of visual diagram

  • Wallace
    2 years ago
    Oct 15, 2010

    Fantastic script. Is there anyway to only show DL nested groups and not security groups?

  • Anne
    2 years ago
    Mar 02, 2010

    The problems in the article have been fixed. Thanks for letting us know about them, and thanks for reading! -Anne Grubb, web & developer editor, Windows IT Pro and DevConnections

  • Don
    2 years ago
    Mar 02, 2010

    Cannot find Dowload the Code Here button!

  • RYAN
    2 years ago
    Feb 15, 2010

    First of all thanks for a great article. This type of thing is handy in dealing with compliance auditors.

    Second thanks for posting a script that's not PowerShell. I'm finding people are adapting PowerShell to things where it doesn't really fit just for the sake of being trendy.

    One piece of advice: Good AD administrators will have long, descriptive group names. I've had several issues with a similar .vbs bombing out over group names that exceeded the Excel's character limitations. If you're looking for a work-around to this there's one here: http://www.ryanboyer.net/group-membership/.

    You'll also find solutions for selectively auditing especially sensitive groups rather than every group across your (potentially) huge enterprise.

    Again - thanks for a terrific article. I keep subscribing to your magazine and interest groups because of useful articles like this one.

    -Tallarico
    Also - for

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.