Solved

Export distribution from AD to Excel (nested groups)

Posted on 2006-11-14
3
722 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
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 500 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

746 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

8 Experts available now in Live!

Get 1:1 Help Now