Extracting Distribution List information in Exchange

This was due for quite some time, & I spent good two days for this. keeping it short , here is a Script that extracts all DL's ( including Query based), their DL managers, number of members & the restriction if any on the DL's .needless to say this was one of the task I loved







Modify the values:

 

strServerGC="SERVERNAME"

strDN="dc=ROOT,dc=com"

strFileName="dl-dn-dump.txt"

Use following Script

-------------------------------------------------------------------------------------------------------------------------------------------------------
'Script dumps all DL Names, DL Restrictions, Mananged by and number
'  of members including Query-based to a text file
'  separated by semi-colons.  Open in Excel for easy formatting

strServerGC="SERVERNAME"
strDN="dc=ROOT,dc=com"
strFileName="dl-dn-dump.txt"

' Create file
Set objFSO = CreateObject("Scripting.FileSystemObject")

'If objFSO.FileExists("dl-Restriction-dump.txt") Then
'    objFSO.DeleteFile("dl-Restriction-dump.txt")
'End If
Set dlDumpFile = objFSO.CreateTextFile(strFileName,true)
dlDumpFile.writeline "DL Name;Restriction Set;Resticted To;Managed By;Number of Members"
'Initailize DB Conneciton
set objConn=CreateObject("ADODB.Connection")
objConn.Provider="ADSDSOObject"
objConn.Open

set objRS=objConn.Execute _
 ("<LDAP://" & strDN & " >;(&(|(objectclass=Group)(objectClass=msExchDynamicDistributionList))(mailNickname=*));" _
 & "ADsPath;SubTree")
while not objRS.EOF
     set objGroup=GetObject(objRS.Fields("adspath"))
  'wscript.echo objGroup.displayName
  ProcessUsers(objGroup)
  objRS.moveNext
Wend
 

function getDisplayName(objDN)

   Set objGroup=GetObject("LDAP://" & strServerGC & "/" & objDN)
   DisplayName=objGroup.DisplayName
   getDisplayName=DisplayName
End Function
 
Sub ProcessUsers(objUsers)
 On Error Resume Next
 countMems = 0
 'wscript.Echo objUsers.Name
 set objPD = GetObject("LDAP://"& _
 objUsers.distinguishedName)
 groupName = objPD.displayName
 groupManager = getDisplayName(objPD.managedBy)
 delegateList = objPD.GetEx("authOrig")
 'Users allowed to send 
 For Each Desc In delegateList
     displayName=getDisplayName(Desc)
     authList=authList & displayName & ","
 Next
 'DL's allowed to send
 dlMemList = objPD.GetEx("dLMemSubmitPerms")
 For Each dlMem In dlMemList
    dlDName=getDisplayName(dlMem)
    dlAuthList = dlAuthList & dlDName & ","
 Next
 'Number of members
     numOfMembers = objPD.GetEx("member")
  For each Mem In numOfMembers
   countMems = countMems+1
                'Uncomment memNames to add member names to the export
  'memNames getDisplayName(Mem)
  Next
 set objPD = Nothing
 if len(authList)>5 OR len(dlAuthList)> 5 then
  restrictionSet = "Yes"
 end if
 
 dlDumpFile.writeLine groupName & ";" & restrictionSet & ";" &  authList & dlAuthList  & ";" & groupManager & ";" & countMems ' & ";" & memNames
End Sub  

-------------------------------------------------------------------------------------------------------------------------------------------------------

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments

  • Tuesday, August 18. 2009 john weber wrote:
    Nice work sandeep !!!
    Reply to this
    1. Wednesday, August 19. 2009 Sandeep Narkhede wrote:
      Thanks John !!
      Reply to this
  • Thursday, September 03. 2009 Dominic wrote:
    For exporting a single DL's members try this script:


    csvde -f DLreport.txt -r "memberOf=cn=MyList,ou=Sales,dc=MyDomain,dc=co m" -l
    sAMAccountName,displayName,mail



    ldifde -f report.txt -r "memberOf=cn=MyList,ou=Sales,dc=MyDomain,dc=co m" -l
    sAMAccountName,displayName,mail

    You must specify the full distinguished name of the distribution group.


    Then you can import this txt file in Excel, using comma as seprator in the sheer.

    how to import this in excel: open excel-- data .. import .. .. then follow the instructions. Commnet your questions here.
    Reply to this
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name (required)

 Email (will not be published) (required)

Your comment is 0 characters limited to 3000 characters.