This blog is by design...

Wednesday, March 22, 2006

Report of all users with a mailbox, mail server name & store name

By taking my lost post we can easily modify that to give us a basic report of all users along with with the mail server their mailbox resides on and which mail store their mailbox is in. Although it's possible to clip the CN= out of the results using vbscript, it's much easier to just import the text file that gets created into excel, select the entire column and do a replace on CN= and simply put nothing in the replace line. This nicely and neatly removes the CN= value allowing you to better sort. You can also clip any uneeded columns in there as well as there will be several that will likely be of no use. When importing the file into excel select both the comma and the semicolon as delimeters. Enjoy!

'***************************************************
'Kris Waters, http://krisdev.blogspot.com
Const ForWriting = 2
Const OpenAsASCII = 0
strOutputFile = "c:\Mail_report.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.sn & ";" & _
objUser.givenName &";"& objUser.homemdb
End If

objRecordSet.Movenext

Wend

Wscript.Echo "All Done"

objOutputFile.close

Monday, March 20, 2006

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"

Tuesday, March 14, 2006

AD Exchange Mailbox Quota Report

The following vbscript will generate a report of all mailbox enabled users in Active Directory who have the 'Use mailbox store defaults' tickbox UN checked. It will also give you the value, if any, that is set in the 'Issue warning at (KB)' field and the 'Prohibit send at (KB)' fields. Enjoy!

'******************************************************
Set objRootDSE = GetObject("LDAP://rootDSE")
strDomain = "LDAP://"& objRootDSE.Get("defaultNamingContext")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutputFile=objFSO.CreateTextFile("c:\MBQuotas.txt",True)


Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = "<"& strDomain &">;"& _
"(objectCategory=user)" & _
";distinguishedName,displayName,mDBUseDefaults,homemdb,"& _
"mDBOverQuotaLimit,mDBStorageQuota;subtree"

objCommand.Properties("Page Size") = 6000

Set objRecordSet = objCommand.Execute

While Not objRecordSet.EOF

'Make sure there is NO linewrap in the following line
if objRecordSet.Fields("mDBUseDefaults") = FALSE AND objRecordSet.Fields("homemdb") <> "" then

strOutput = objRecordSet.Fields("displayName") & ";" & _
objRecordSet.Fields("mDBOverQuotaLimit") & _
";" & objRecordSet.Fields("mDBStorageQuota")
objOutputFile.WriteLine strOutput
end if
objRecordSet.MoveNext
Wend

wscript.Echo "All Done"