Sometimes your clients need to get an overview of who’s getting all the mails for the various distribution groups they’ve had you create. Sometimes they forget who’s been added or removed. I use this script to give them an up-to-date view of where the mail is going.
Basically, we query Active Directory for groups that have an email address. After iterating for members, we do a look up to get the common name so that the user can be displayed properly. The output is a distribution group member listing, along with the email address and aliases of the groups themselves:
Option Explicit
'Declare our variables
Dim adoLDAPCon, adoLDAPRS, strLDAP, strDomainName, objNetwork
Dim strDN, objUser, colAddr, strAddr, objMember
' Grab the domain name
Set objNetwork = CreateObject("Wscript.Network")
strDomainName = objNetwork.UserDomain
' Create an ADO DB connection through ADSI to get a list of users and public folders
Set adoLDAPCon = CreateObject("ADODB.Connection")
adoLDAPCon.Provider = "ADsDSOObject"
adoLDAPCon.Open "ADSI"
strLDAP = "'LDAP://" & strDomainName & "'"
WScript.Echo "Getting mail addresses from " & strLDAP
Set adoLDAPRS = adoLDAPCon.Execute("select ADsPath from " & strLDAP & _
" WHERE objectClass = 'group'")
While Not adoLDAPRS.EOF
strDN = adoLDAPRS.Fields("ADsPath").value
Set objUser = GetObject(strDN)
' Only try to display if the object has "proxyAddresses" set
If Not IsEmpty(objUser.proxyAddresses) Then
colAddr = objUser.GetEx("proxyAddresses")
For Each strAddr in colAddr
strAddr = LCase(strAddr)
If Left(strAddr, 5) = "smtp:" And Right(strAddr, 6) <> ".local" Then _
Wscript.Echo objUser.cn & ": " & Mid(strAddr, 6)
Next
End If
If Not IsEmpty(objUser.member) Then
colAddr = objUser.GetEx("member")
For Each strAddr in colAddr
strAddr = mid(strAddr, 4, InStr(strAddr, ",") - 4)
Wscript.Echo " " & strAddr
Next
End If
Set objUser = Nothing
adoLDAPRS.MoveNext
Wend
adoLDAPRS.Close
Set adoLDAPRS = Nothing
Set adoLDAPCon = Nothing
Usually, I just run it like this:
C:\> cscript //nologo ShowGroup.vbs
Thanks, and let me know if you find this helpful.
