'Set up constant for deleting values from multivalued attribute memberOf Const ADS_PROPERTY_NOT_FOUND = &h8000500D Const ADS_UF_ACCOUNTDISABLE = 2 Const strX400Search = "X400" Const ForAppending = 8 'Set RootDSE Set objRootDSE = GetObject("LDAP://rootDSE") strDomain = objRootDSE.Get("defaultNamingContext") strADPath = "LDAP://" & strDomain WScript.Echo "LDAP Path: " & strADPath ' Get domain Set objDomain = GetObject(strADPath) WScript.echo "objDomain: " & objDomain.distinguishedName 'Setup ADODB connection Set objConnection = CreateObject("ADODB.Connection") objConnection.Open "Provider=ADsDSOObject;" Set objCommand = CreateObject("ADODB.Command") objCommand.ActiveConnection = objConnection ' Execute search command to look for Groups objCommand.CommandText = "<" & strADPath & ">" & ";(&(objectClass=group)(mail=*))" & ";distinguishedName,displayName,mail,proxyAddresses;subtree" 'Execute search to get Recordset objCommand.Properties("Page Size") = 2000 Set objRecordSet = objCommand.Execute WScript.Echo "Total Records Found: " & objRecordSet.RecordCount & VbCrlf WScript.Echo "Enumerating groups..." While Not objRecordSet.EOF strUserDN = objRecordSet.Fields("distinguishedName") set objUser= GetObject("LDAP://"& strUserDN & "") strResult1 = strResult1 & objUser.cn & "," & objUser.mail arrProxyAddresses = objRecordSet.Fields("proxyAddresses") If IsArray(objRecordSet.Fields("proxyAddresses")) Then For Each ProxyAddress in arrProxyAddresses If InStr(ProxyAddress, strX400Search) <> 0 Then 'Wscript.Echo "This is an X400 address" Else ' Only add SMTP addresses If Lcase(Left(proxyAddress,5)) = "smtp:" Then strTempAddr = LCase(Mid(proxyAddress,6)) If Not strTempAddr = Lcase(objUser.mail) Then strResult1 = strResult1 & vbCrLf & strTempAddr End If End If End If Next End If strResult1 = strResult1 & VbCrLf objRecordSet.MoveNext Wend '************************************* 'Begin second query for users ' Execute search command to look for user objCommand.CommandText = "<" & strADPath & ">" & ";(&(objectClass=user)(mail=*))" & ";distinguishedName,displayName,mail,proxyAddresses;subtree" ' Execute search to get Recordset objCommand.Properties("Page Size") = 2000 Set objRecordSet = objCommand.Execute WScript.Echo "Enumerating users..." While Not objRecordSet.EOF 'Iterate through the search results strUserDN = objRecordSet.Fields("distinguishedName") set objUser= GetObject("LDAP://"& strUserDN & "") If Not objUser.AccountDisabled = TRUE Then strResult2 = strResult2 & objUser.mail arrProxyAddresses = objRecordSet.Fields("proxyAddresses") If IsArray(objRecordSet.Fields("proxyAddresses")) Then For Each ProxyAddress in arrProxyAddresses If InStr(ProxyAddress, strX400Search) <> 0 Then 'Wscript.Echo "#This was an x400" Else ' Only add SMTP addresses If Lcase(Left(proxyAddress,5)) = "smtp:" Then strTempAddr = LCase(Mid(proxyAddress,6)) ' Add each users email address If Not strTempAddr = Lcase(objUser.mail) Then strResult2 = strResult2 & vbCrLf & strTempAddr End If End If End If Next End If strResult2 = strResult2 & VbCrLf End If objRecordSet.MoveNext Wend WScript.Echo vbCrLf & "Done" ' File system object Set objFileSystem = CreateObject("Scripting.FileSystemObject") ' Output groups to text file Set objOutputFile = objFileSystem.CreateTextFile("EFSUSERS.TXT") objOutputFile.Write strResult1 objOutputFile.Close ' Append users to text file Set objOutputFile = objFileSystem.OpenTextFile("EFSUSERS.TXT", ForAppending, True) objOutputFile.Write strResult2 objOutputFile.Close