Thursday, October 21, 2004

Last 5 received/Sent Emails IPAQ pocket IE page/script

I been playing around with some WebDAV code with Pocket IE (on a IPAQ)to display a screen that shows me the last 5 emails I received and the last 5 I sent. Because my IPAQ sits on my desk most of the day doing nothing I found this pretty handy as it alloys me to see at a glance which bit of email I need to take action on and what I've replied to recently. Geting the code to work inside of pocket IE was a little bit of a challendge had to switch to using Jscript and I found out that a few things that worked fine in the desktop version of IE don't work the way you really want them to (or at all) in the pocket version of IE but I did manage to come up with the following piece of working code. Basically what it does is performs two separate WebDAV queries the first one of the Inbox and then the Sent Items folder. I used the Range header to limit the result set of the queries to 5 rows. The Range header is pretty cool it kind of a sudo SQL TOP statement. I've added some simple HTML that displays unread email in a different colour and bold and the last part of the code sets up a ongoing timer which does a query of the mailbox every 25 seconds to see if any new mail has arrived or the read status of a mail has change. It does this by making another query of the inbox and then compares the received time of the last mail it received to the one it retrieved in the first query of that email along with the read status as well. If any of these are different then it initiates a page reload. The page itself is just a HTM page you copy to your IPAQ (after you mod the code to put in your mailbox and server you need to connect to). I've put a copy of the code up here

Tuesday, October 12, 2004

Listing the file sizes of all Exchange Stores on all Exchange Servers in a Domain

One of the things that I've found missing from the Exchange Management GUI's has been the ability to get the physical size of the database files (especially when you have multiple servers to manage). None of the Exchange API's accessible with script offer this type of information either.

I've found two methods you can use to grab this information via a script, the first is when the information store performs a backup via the Exchange Backup API one of the events it logs is event code 220 which states the size of each file before it is backed up. The other method is to connect to the file using the FSO object in VBS and grab the size of the file directly.

I've expanded this second method into a script that first queries for all the msExchPrivateMDB and msExchPulicMDB objects in Active Directory using ADSI. Then using the msExchEDBFile, msExchSLVFile and msExchOwningServer AD properties constructs the URL to be able to connect to each file remotely and report on the size of the EDB and STM files for that mail or public folder store. I've also used the homeMDBBL property which contains a list of all the mailenabled accounts within a mailstore to get the number of mailboxes for each mailstore. The script itself is designed to be run from the command line using cscript and will produce a console output for every Exchange server store for the domain its runs in.

The script itself looks like this I've posted a download-able copy up here

set conn = createobject("ADODB.Connection")
set com = createobject("ADODB.Command")
Set iAdRootDSE = GetObject("LDAP://RootDSE")
strNameingContext = iAdRootDSE.Get("configurationNamingContext")
Conn.Provider = "ADsDSOObject"
Conn.Open "ADs Provider"
mbQuery = ";(objectCategory=msExchPrivateMDB);name,distinguishedName;subtree"
pfQuery = ";(objectCategory=msExchPublicMDB);name,distinguishedName;subtree"
Com.ActiveConnection = Conn
Com.CommandText = mbQuery
Set Rs = Com.Execute
Wscript.echo "Mailbox Stores"
Wscript.echo
While Not Rs.EOF
objmailstorename = "LDAP://" & Rs.Fields("distinguishedName")
set objmailstore = getObject(objmailstorename)
objmailstore.GetInfoEx Array("homeMDBBL"), 0
varReports = objmailstore.GetEx("homeMDBBL")
Set fso = CreateObject("Scripting.FileSystemObject")
edbfilespec = "\\" & mid(objmailstore.msExchOwningServer,4,instr(objmailstore.msExchOwningServer,",")-4) & "\" & left(objmailstore.msExchEDBFile,1) & "$" & mid(objmailstore.msExchEDBFile,3,len(objmailstore.msExchEDBFile)-2)
stmfilespec = "\\" & mid(objmailstore.msExchOwningServer,4,instr(objmailstore.msExchOwningServer,",")-4) & "\" & left(objmailstore.msExchSLVFile,1) & "$" & mid(objmailstore.msExchSLVFile,3,len(objmailstore.msExchSLVFile)-2)
Set efile = fso.GetFile(edbfilespec)
set sfile = fso.GetFile(stmfilespec)
edbsize = formatnumber(efile.size/1073741824,2,0,0,0)
stmsize = formatnumber(sfile.size/1073741824,2,0,0,0)
Wscript.echo Rs.Fields("name") & "# Mailboxes: " & ubound(varReports)+1 & " EDBSize(GB): " & edbsize & " STMSize(GB): " & stmsize
Rs.MoveNext

Wend
Wscript.echo
Wscript.echo "Public Folder Stores"
Wscript.echo
Com.CommandText = pfQuery
Set Rs1 = Com.Execute
While Not Rs1.EOF
objmailstorename = "LDAP://" & Rs1.Fields("distinguishedName")
set objmailstore = getObject(objmailstorename)
Set fso = CreateObject("Scripting.FileSystemObject")
edbfilespec = "\\" & mid(objmailstore.msExchOwningServer,4,instr(objmailstore.msExchOwningServer,",")-4) & "\" & left(objmailstore.msExchEDBFile,1) & "$" & mid(objmailstore.msExchEDBFile,3,len(objmailstore.msExchEDBFile)-2)
stmfilespec = "\\" & mid(objmailstore.msExchOwningServer,4,instr(objmailstore.msExchOwningServer,",")-4) & "\" & left(objmailstore.msExchSLVFile,1) & "$" & mid(objmailstore.msExchSLVFile,3,len(objmailstore.msExchSLVFile)-2)
Set efile = fso.GetFile(edbfilespec)
set sfile = fso.GetFile(stmfilespec)
edbsize = formatnumber(efile.size/1073741824,2,0,0,0)
stmsize = formatnumber(sfile.size/1073741824,2,0,0,0)
Wscript.echo Rs1.Fields("name") & " EDBSize(GB): " & edbsize & " STMSize(GB): " & stmsize
Rs1.MoveNext

Wend
Rs.Close
Rs1.Close
Conn.Close
Set Rs = Nothing
set Rs1 = Nothing
Set Com = Nothing
Set Conn = Nothing

Friday, October 08, 2004

Getting Meeting Attendee status and roles through WebDAV

When you send out meeting or appointment invites to people and they are accepted or denied by users the status of there acceptance (and their role in the Meeting) is stored in the recipients collection of the appointment object. In CDOEX you have a few interfaces that allow you to interrogate and retrieve this information via the IAppointment and IAttendee interfaces. EG

set apptobj = createobject("CDO.Appointment")
apptobj.datasource.open "file://./backofficestorage/domain.com.au/MBX/mailbox/calendar/appointment.EML"
for each attend in apptobj.Attendees
wscript.echo attend.address
wscript.echo attend.role
wscript.echo attend.status
next

In WebDAV access to the recipients collection of a message is very limited and usually all you can retrieve is the email address and or displayname of each attendee. A while ago I blogged this about a method of accessing a meeting resource's email address by using the vCalendar body part of an appointment. The attendee status and attendee role are also stored in this vCalendar body part so you can extend this method to also parse out the attendee Role and attendee Status from this body part. Here's what it looks like in script. If you want to download a copy I've put it up here

set Req = createobject("Microsoft.XMLHTTP")
Req.open "GET", "http://server/exchange/mailbox/Calendar/appoinment.EML", false
Req.setRequestHeader "Translate","f"
Req.send
attendeearry = split(req.responsetext,"ATTENDEE;",-1,1)
for i = 1 to ubound(attendeearry)
string1 = vbcrlf & " "
stparse = replace(attendeearry(i),string1,"")
attaddress = mid(stparse,(instr(stparse,"MAILTO:")+7),instr(stparse,chr(13)))
attaddress = mid(attaddress,1,instr(attaddress,vbcrlf))
attrole = mid(stparse,(instr(stparse,"ROLE=")+5),instr((instr(stparse,"ROLE=")+5),stparse,";")-(instr(stparse,"ROLE=")+5))
attstatus = mid(stparse,(instr(stparse,"PARTSTAT=")+9),instr((instr(stparse,"PARTSTAT=")+9),stparse,";")-(instr(stparse,"PARTSTAT=")+9))
wscript.echo attaddress
wscript.echo attrole
wscript.echo attstatus
next