?
Solved

Export distribution from AD to Excel (nested groups)

Posted on 2006-11-14
3
Medium Priority
?
728 Views
Last Modified: 2010-10-05
Using this as a guide:

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21311589.html

Works great!

I need to be able to export distribution list members from a distribution list that contains other distribution lists.

How do I modify the script to get to drill down into the nested group and return the members?
0
Comment
Question by:trarthur
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 18016607
Try this modified version.

Dim objGroup, objExcel, objSheet, iRow, objMemberPath, objMember
Set objGroup = GetObject("LDAP://CN=myDistList,ou=Messaging,dc=myDomain,dc=com")

Set objExcel = CreateObject("Excel.Application")
With objExcel
  .SheetsInNewWorkbook = 1
  .Workbooks.Add
  .Visible = True
  Set objSheet = .Worksheets.Item(1)
  .Worksheets.Item(1).Name = mid(objGroup.Name, instr(1,objGroup.Name,"=") + 1 ) 'set Worksheet name to that of the DL
  irow=1

 For Each objMemberPath in objGroup.Members
    Set objMember = GetObject(objMemberPath.ADsPath)
    If objMember.Class = "group" Then
        ProcessGroup objMember
    Else
        objSheet.Cells(iRow,1) = objMember.ADsPath
        irow=irow + 1
    End If
 Next
 .Columns(1).entirecolumn.autofit
End With

objExcel.ActiveWorkbook.SaveAs "C:\eeTesting\Group Members.xls"
Set objSheet = Nothing
Set objExcel = Nothing
Set objGroup = Nothing  
Set objMember = Nothing
Set objMemberPath = Nothing
WScript.Quit


Sub ProcessGroup(objGroup)
    Dim objMemberPath, objMember
    For Each objMemberPath In objGroup.Members
        Set objMember = GetObject(objMemberPath.ADsPath)
        If objMember.Class = "group" Then
            ProcessGroup objMember
        Else
            objSheet.Cells(iRow,1) = objMember.ADsPath
            irow=irow + 1
        End If
    Next
    Set objMemberPath = Nothing
    Set objMember = Nothing
End Sub
0
 
LVL 76

Expert Comment

by:David Lee
ID: 18371789
Recommend accepting my initial post.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

743 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