WMI: get the last logon and logged on user from an exchange mailbox
The script below uses the Exchange server and the legacyExchangeDN as input and outputs the mailbox last logon time in Exchange and the connected user.
On Error Resume Next
strExchangeServer = wscript.arguments(0)
strLegacyExchangeDN = UCase(wscript.arguments(1))
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" & strExchangeServer & _
"ROOTMicrosoftExchangeV2")
Set colItems = objWMIService.ExecQuery _
("Select * from Exchange_Mailbox where LegacyDN = '" & strLegacyExchangeDN & "'")
For Each objItem in colItems
If objItem.LegacyDN = strLegacyExchangeDN Then
wscript.echo objItem.LastLogonTime
wscript.echo objItem.LastLoggedonUserAccount
End If
Next