For all users that have an Exchange mailbox, write ALL their email addresses to a file
Although this can be done with ldifde, or possibly with csvde, I've never been terribly skillful with either of those utilities. So, this little vbscript will scrub your AD looking for anyone that has a value in the homemdb attribute. This generally means they have a mailbox on an exchange server somewhere, and thus should have an smtp addres in the proxyAddresses value in AD. This script does user accounts only, not contacts, groups, or anything else that might have an smtp address. If you're trying to search your domain for a particular smtp address to see where it's being used I have a script that does that as well, located here.
This is a pretty standard script, it uses a sql type query to gather all user accounts, then does some standard looping to sort out the ones that actually have mailboxes. Since the proxyAddresses attribute is 'multivalued', meaning that it can hold more than one entry, we have to sort through all the possible entries for that value. I also incorporated some string searches to drop the X400 address and any holdover MBX values so we get a nice list of JUST smtp addresses.
'***************************************************
On Error Resume Next
Const ForWriting = 2
Const OpenAsASCII = 0
strOutputFile = "c:\SmtpAdds.txt"
Set objRootDSE = GetObject("LDAP://rootDSE")
strDomain = "LDAP://"& objRootDSE.Get("defaultNamingContext")
Set objFSO = CreateObject("scripting.filesystemobject")
Set objOutputFile = objFSO.CreateTextFile _
(strOutputFile, ForWriting, OpenAsASCII)
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = "<"& strDomain &">;(objectCategory=person)" & _
";distinguishedName,cn;subtree"
objCommand.Properties("Page Size") = 6000
Set objRecordSet = objCommand.Execute
While Not objRecordSet.EOF
strUserDN = objRecordSet.Fields("DistinguishedName")
set objUser = GetObject("LDAP://"& strUserDN)
If instr(objUser.homemdb,"CN=") <> 0 then
objOutputfile.writeline objUser.displayName
For Each entry in objUser.GetEx("proxyAddresses")
If instr(entry,"X400") = 0 Then
proxy1 = entry
If instr(proxy1, "MBX:") = 0 Then
objOutputfile.writeline proxy1
End If
End If
Next
objOutputfile.writeline
End If
objRecordSet.MoveNext
Wend
objConnection.Close
Set objRootDSE = Nothing
set objConnection = Nothing
set objCommand = Nothing
set objRecordSet = Nothing
set objUser = Nothing
set objOutputFile = Nothing
set objFSO = Nothing
wscript.Echo "All Done"
This is a pretty standard script, it uses a sql type query to gather all user accounts, then does some standard looping to sort out the ones that actually have mailboxes. Since the proxyAddresses attribute is 'multivalued', meaning that it can hold more than one entry, we have to sort through all the possible entries for that value. I also incorporated some string searches to drop the X400 address and any holdover MBX values so we get a nice list of JUST smtp addresses.
'***************************************************
On Error Resume Next
Const ForWriting = 2
Const OpenAsASCII = 0
strOutputFile = "c:\SmtpAdds.txt"
Set objRootDSE = GetObject("LDAP://rootDSE")
strDomain = "LDAP://"& objRootDSE.Get("defaultNamingContext")
Set objFSO = CreateObject("scripting.filesystemobject")
Set objOutputFile = objFSO.CreateTextFile _
(strOutputFile, ForWriting, OpenAsASCII)
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = "<"& strDomain &">;(objectCategory=person)" & _
";distinguishedName,cn;subtree"
objCommand.Properties("Page Size") = 6000
Set objRecordSet = objCommand.Execute
While Not objRecordSet.EOF
strUserDN = objRecordSet.Fields("DistinguishedName")
set objUser = GetObject("LDAP://"& strUserDN)
If instr(objUser.homemdb,"CN=") <> 0 then
objOutputfile.writeline objUser.displayName
For Each entry in objUser.GetEx("proxyAddresses")
If instr(entry,"X400") = 0 Then
proxy1 = entry
If instr(proxy1, "MBX:") = 0 Then
objOutputfile.writeline proxy1
End If
End If
Next
objOutputfile.writeline
End If
objRecordSet.MoveNext
Wend
objConnection.Close
Set objRootDSE = Nothing
set objConnection = Nothing
set objCommand = Nothing
set objRecordSet = Nothing
set objUser = Nothing
set objOutputFile = Nothing
set objFSO = Nothing
wscript.Echo "All Done"


11 Comments:
Smoking Script. Just what I needed before I upgrade to Exch2003 from Exch2000. Shouldn't need the address list.. but you never know.
By
Anonymous, at 2:21 PM
Glad you found it useful, thanks for taking the time to comment :)
By
kristinaw, at 7:35 PM
By the way, if you have more than 6000 user objects in your domain just change this line: objCommand.Properties("Page Size") = 6000 to match your needs.
By
kristinaw, at 7:37 PM
Just a clue...
What about the emails assigned to groups?
By
Anonymous, at 3:33 AM
If you want to get props for a group, just change the line that says 'person' to 'group'. I think that should work.
By
kristinaw, at 10:17 AM
echo what 1st reply said: smoking!
very neat script and gives me some confidence to use VBScript for other stuff too. I wanted a way to get GAL data into a SQL db, and this seems the least effort way to do it...
By
Anonymous, at 9:38 AM
This script worked very nice and fast! Just wondering if there is any way to get it to write the .txt file in alphabetical order.
Thanks for the script!!
Mike
By
Mike, at 12:34 PM
Excellent!!! Thank you very mucho!!!
By
Anonymous, at 3:27 PM
情趣,情趣用品,
SM,G點,按摩棒,
飛機杯,充氣娃娃,
自慰套,情趣用具,
情趣味用品浪漫巴黎,情趣味用品,
情趣用品,情趣,
按摩棒,角色扮演,
性感睡衣,自慰器,
跳蛋,吊帶襪,
情趣內衣,充氣娃娃,
情趣味用品浪漫巴黎,
By
Anonymous, at 2:20 AM
شركة كشف تسربات المياه بالدمام
شركة تسليك مجارى بالقطيف
By
Unknown, at 12:55 PM
كل هذه الخدمات واكثر من خلال شركة نقل عفش من الرياض الى الاردن افضل الخدمات الاساسية المميزة التى تساعد فى الوصول الى افضل النتائج المثاليه بالاضافة الى ان اعمال النقل تتم منذ لحظة اتصال عملاءنا الكرام بالشركة والبدء فى اعمال النقل منذ لحظة اتفاق مع عملاءنا الكرام فاذا اراد ان تشعر بالتميز بينا وبين اى شركة اخرى تقوم باعمال النقل واراد ان تشعر بالتميز والحفاظ على الاثاث دون ان يتاثر بالتغيرات التى تطرا على المكان فاعلم ان
شركة نقل عفش من الرياض الى دبي هى الحل الامثل فى القيام بهذه الخدمة على الفور
https://khalejmovers.com/
By
نور الهدى, at 1:43 AM
Post a Comment
<< Home