How to find Last Accessed date

Posted on 2010-01-04
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
    LVL 70

    Expert Comment

    by:Chris Dent

    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

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

    Accepted Solution


    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


    Author Comment

    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 70

    Expert Comment

    by:Chris Dent

    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

    Thx a Lot !!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
    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 (…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now