Export receipts.vbs
'================================================================================================== ' NAME: PostfixAddressExtract.VBS ' VERSION: 1.0 ' AUTHOR: Bharat Suneja (altered by Lee Monamy) ' LAST MODIFIED : 16/08/2007 '================================================================================================== ' COMMENT: Based on LISTPROXYADDRESSES.VBS/LISTEMAILADDRESSES.VBS by Bharat Suneja ' http://exchangepedia.com/blog/2005/09/how-to-export-all-email-addresses-from.html ' but altered to: ' o strip out cn, mail, etc entries ' o strip out .local addresses ' o remove a bunch of extra CRLFs ' o remove the "SMTP:" or "smtp:" prefix from addresses (x = Right(x), Len(x) -5)) ' o put the display name commented out just before the email addresses ' o append " OK" after just the email address (sans SMTP: prefix) ' Run the script (double-click) and the output appears in a dialog. It is also written ' to C:\proxyaddresses.txt. You should be able to copy this file to your spam filter and ' simply postmap it with no further processing required. ' DISCLAIMER: THIS SCRIPT IS ENTIRELY UNSUPPORTED. USE AT YOUR OWN RISK. NOBODY BUT YOU ' IS RESPONSIBLE IF THIS SCRIPT DELETES THE CONTENTS OF YOUR ACTIVE DIRECTORY OR SETS FIRE ' TO YOUR CAT. CAVEAT EMPTOR. ' LICENCE: Unknown, as this is pretty much Bharat Suneja's script with minor changes, and ' there was no licence mentioned originally. Otherwise, LGPL. Do what you like. ' This has been tested on several SBS 2003 installations and Works For Me, and does what I ' need. I hope you find it useful. ' Thanks to Gary V (http://www200.pair.com/mecham/spam/) & freespamfilter.org for their ' truly excellent documentation! '==================================================================================================
'Set up constant for deleting values from multivalued attribute memberOf
Const ADS_PROPERTY_NOT_FOUND = &h8000500D Const ADS_UF_ACCOUNTDISABLE = 2 'For UserAccountControl Const strX400Search = "x400" Const LocSearch = ".local" '______________________________________________________
'Set RootDSE Set objRootDSE = GetObject("LDAP://rootDSE") strDomain = objRootDSE.Get("defaultNamingContext") strADPath = "LDAP://" & strDomain 'wscript.Echo strADPath 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 Contacts & Groups objCommand.CommandText = _ "<" & strADPath & ">" & ";(&(|(objectClass=contact)(objectClass=group))(mail=*))" & ";distinguishedName,displayName,mail,proxyAddresses;subtree"
'Execute search to get Recordset Set objRecordSet = objCommand.Execute 'Start procedure strResult = strResult & VbCrLf & "# Domain: " & strDomain
strResult = strResult & VbCrlf & "#Total Records Found (other accounts, distribution groups): " & objRecordSet.RecordCount & VbCrlf AddressCount = 0
While Not objRecordSet.EOF 'Iterate through the search results strUserDN = objRecordSet.Fields("distinguishedName") 'Get User's distinguished name from Recordset into a string set objUser= GetObject("LDAP://"& strUserDN & "") 'Use string to bind to user object
arrProxyAddresses = objRecordSet.Fields("proxyAddresses") If IsArray(objRecordSet.Fields("proxyAddresses")) Then For Each ProxyAddress in arrProxyAddresses 'Sub: Check X400 If InStr(LCase(ProxyAddress), strX400Search) <> 0 Then 'Wscript.Echo "#This was an x400" Else If InStr(1, ProxyAddress, LocSearch, 1) = 0 Then proxyAddress = Right(proxyAddress, Len(proxyAddress) -5 ) strResult = strResult & VbCrlf & proxyAddress & " OK" End If End If 'Ends loop for X400 address Next
Else strResult = strResult & VbCrlf & "#Object does not have proxy addresses" End If 'strResult = strResult & VbCrLf
objRecordSet.MoveNext Wend
'************************************* 'Begin second query for users varDisabledCounter = 0
'Execute search command to look for user objCommand.CommandText = _ "<" & strADPath & ">" & ";(&(objectClass=user)(mail=*))" & ";distinguishedName,displayName,mail,proxyAddresses;subtree"
'Execute search to get Recordset Set objRecordSet = objCommand.Execute strResult = strResult & vbCrlf & vbCrlf & "#Users" strResult = strResult & VbCrlf & "#Total Records Found (users): " & objRecordSet.RecordCount
While Not objRecordSet.EOF 'Iterate through the search results strUserDN = objRecordSet.Fields("distinguishedName") 'Get User's distinguished name from Recordset into a string set objUser= GetObject("LDAP://"& strUserDN & "") 'Use string to bind to user object If objUser.AccountDisabled = TRUE Then 'If User account disabled, then skip proxy address enum varDisabledCounter = varDisabledCounter + 1 strResult2 = strResult2 & VbCrLf & "# " & varDisabledCounter & " " & objUser.displayName & VbCrLf
arrProxyAddresses = objRecordSet.Fields("proxyAddresses") If IsArray(objRecordSet.Fields("proxyAddresses")) Then
For Each ProxyAddress in arrProxyAddresses 'Sub: Check X400 If InStr(LCase(ProxyAddress), strX400Search) <> 0 Then 'Wscript.Echo "#This was an x400" Else If InStr(1, ProxyAddress, LocSearch, 1) = 0 Then proxyAddress = Right(proxyAddress, Len(proxyAddress) -5 ) strResult2 = strResult2 & "# " & proxyAddress & " OK" End If AddressCount = AddressCount + 1 End If 'Ends loop for X400 address Next Else strResult2 = strResult2 & VbCrLf & "#Object does not have proxy addresses" End If 'strResult2 = strResult2 & VbCrLf Else strResult = strResult & VbCrLf & "# " & " " & objUser.displayName arrProxyAddresses = objRecordSet.Fields("proxyAddresses") If IsArray(objRecordSet.Fields("proxyAddresses")) Then For Each ProxyAddress in arrProxyAddresses 'Sub: Check X400 If InStr(LCase(ProxyAddress), strX400Search) <> 0 Then 'Wscript.Echo "#This was an x400" Else If InStr(1, ProxyAddress, LocSearch, 1) = 0 Then proxyAddress = Right(proxyAddress, Len(proxyAddress) -5 ) strResult = strResult & vbCrlf & proxyAddress & " OK" End If AddressCount = AddressCount + 1 End If 'Ends loop for X400 address Next Else strResult = strResult & VbCrLf & "#Object does not have proxy addresses" End If strResult = strResult & VbCrLf End If 'End check for disabled user objRecordSet.MoveNext Wend 'End second query for users
strResult = "# Users, Groups & Contacts" & VbCrLf & "#-------------------------" & VbCrLf & strResult strResult = strResult & VbCrLf & "# Disabled Users" & VbCrLf & "#-------------------------" & VbCrLf & strResult2 'WScript.Echo strResult
'Output to a text file Set objFileSystem = CreateObject("Scripting.FileSystemObject") Set objOutputFile = objFileSystem.CreateTextFile("C:\Inetpub\wwwroot\virtual.txt") objOutputFile.Write strResult