How to find Last Accessed date

Posted on 2010-01-04
Medium Priority
Last Modified: 2012-05-08
I want to make a script to list all mailboxes and the date that mailbox was last access on our Exchange servers.

Does anyone has info on how to get this?

BTW: I have VBscript hands-on experience in getting info from an AD. So I search info and/or code for this specific case.
Question by:Marc_Engrie
  • 3
  • 3
LVL 71

Expert Comment

by:Chris Dent
ID: 26169926

You need to tell us the version of Exchange you want it from. How this information is exposed depends on that, it's not the same from one version to the next.


Author Comment

ID: 26169945
currently we use 2003. We plan to migrate to Exchange 2010 this year. So if possible for both would be great.
LVL 71

Accepted Solution

Chris Dent earned 1000 total points
ID: 26169990

Okie dokie.

For Exchange 2003 you're looking at WMI, no particular limitations on the language you use, both VbScript and PowerShell provide pretty straight-forward access to that.

The VbScript approach is something like the snippet below (I can't test it I'm afraid, I don't run Exchange 2003 anymore).

For Exchange 2010 (and Exchange 2007 if that's relevant) you'll be using PowerShell. Something like this command:

Get-MailboxStatistics | Select-Object DisplayName, LastLogonTime, LastLoggedOnUserAccount

Nice and short :) If you fancy using PowerShell for 2003 I have an implementation of Get-MailboxStatistics for 2003 here:


Note that in all cases Exchange does not give a history of connections, just point in time information.

' Simple VbScript to connect to an Exchange Server and list mailboxes, the last 
' connect date, and the last connected user

strExchServer = "YourExchangeServer"

Function ConvertToDate(strDate)
  ' (Slightly) modified function from the MS Scripting guys WMIDateStringToDate

  If Trim(strDate) = "" Or IsNull(strDate) Then
    ConvertToDate = ""
    ConvertToDate = CDate(Mid(strDate, 7, 2) & "/" & _
      Mid(strDate, 5, 2) & "/" & Left(strDate, 4) & " " & _
      Mid(strDate, 9, 2) & ":" & Mid(strDate, 11, 2) & ":" & Mid(strDate, 13, 2))
  End If
End Function

Set objWMI = GetObject("winmgmts:\\" & strExchServer & "\root\MicrosoftExchangeV2")
Set colMailboxes = objWMI.ExecQuery("SELECT * FROM Exchange_Mailbox")

For Each objItem in colMailboxes
  WScript.Echo objItem.MailboxDisplayName & vbTab & _
    ConvertToDate(objItem.LastLogonTime) & vbTab & _

Open in new window


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Author Comment

ID: 26170057
Your script is working fine on Exchange 2003 !!

I need to get up to speed with POwershell but didn't find the time yet. Exchange 2010 might be the trigger to do so

Do you have info on all possible attributes of the Mailbox collection?

Thx in advance
LVL 71

Expert Comment

by:Chris Dent
ID: 26170116

Yep I know them all :)

You'll find each of this for objItem in the VbScript example above:

LegacyDN (matches Exchange Legacy DN in AD - most of the time)
Size (in Kilobytes)
StorageLimitInfo (a numeric value which I translate with the function below)
DeletedMessageSizeExtended (in Kilobytes)
LastLogonTime (a Date string I run through the converter above)
LastLogoffTime (ditto)
DateDiscoveredAbsentInDs (for disconnected mailboxes, and ditto for formatting)
MailboxGuid (matches mailboxGuid in AD if you fix up the formatting on each side)

And the function for converting the StorageLimitInfo value:

Function ConvertStatusToName(intStatus)
  Select Case intStatus
    Case 1  : ConvertStatusToName = "BelowLimit"
    Case 2  : ConvertStatusToName = "IssueWarning"
    Case 4  : ConvertStatusToName = "ProhibitSend"
    Case 8  : ConvertStatusToName = "NoChecking"
    Case 16 : ConvertStatusToName = "MailboxDisabled"
  End Select
End Function


Author Comment

ID: 26170351
Thx a Lot !!!

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
This script will sweep a range of IP addresses (class c only, and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month15 days, 5 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question