
October 17th, 2012, 06:25 PM
|
|
Contributing User
|
|
Join Date: Jun 2012
Posts: 31
Time spent in forums: 3 h 56 m 5 sec
Reputation Power: 2
|
|
|
Extracting Email Addresses from a Email Distribution List
Hi,
I have the code below which works fine for extracting the email addresses from a distribution group.
The issue is when it tries to recursively get the email and finds a list which has no users or is deactivated it fails there with error :
Active Directory : The directory property cannot be found in the cache.
I want to make sure that it continues after this as well.
Any help pls
strDistListName = "MyDistributionList"
' Get Domain name from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDomain = objRootDSE.Get("DefaultNamingContext")
'WScript.Echo "Connecting to: " & strDomain
Set ADOconn = CreateObject("ADODB.Connection")
ADOconn.Provider = "ADSDSOObject"
ADOconn.Open "ADs Provider"
bstrADOQueryString = "<LDAP://" & strDomain & ">;(cn=" & strDistListName & ");*;subtree"
Set objRS = ADOconn.Execute(bstrADOQueryString)
If objRS.EOF Then
WScript.Echo "List not found."
End If
Set objObject = GetObject(objRS.Fields(0))
recurse_list objRS.Fields(0), 0
objRS.Close
ADOconn.Close
Set objRS = Nothing
Set ADOconn = Nothing
Set objObject = Nothing
Private Function recurse_list(strPath, intLevel)
Set objObject = GetObject(strPath)
objMembers = objObject.GetEx("member")
For Each member In objMembers
Set objMember = GetObject("LDAP://" & member)
If objMember.Class = "group" Then
WScript.Echo Space(intLevel * 3) & "GROUP: " & objMember.cn
recurse_list objMember.ADsPath, intLevel + 1
Else
If Instr(objMember.distinguishedName, "OU=Disabled Accounts") = 0 Then
WScript.Echo Space(intLevel * 3) & objMember.cn
End If
End If
Set objLocMember = Nothing
Next
End Function
Thanks-
|