Exchange 2010 get list of mailboxes with logon time information

Below you can find script which will return all mailboxes where LastLogonTime is older than 90 days ago.

You can easly set this date in variable $days.

 

Function New-Array {,$args}
$Report = New-Array

$days = "90"

$date_last = (Get-Date).AddDays(-$days) 
$mailboxes = Get-Mailbox -server mxmbx01 -ResultSize unlimited

foreach($mailbox in $mailboxes) 
{ 
  $mbx_DN = $mailbox.DistinguishedName 
  $email = $mailbox.PrimarySmtpAddress.toString()
  $Stat = Get-MailboxStatistics -Identity $mbx_DN | Where-Object {$_.lastLogonTime -lt $date_last} | Select-Object DisplayName, totalitemsize,LastLogonTime

 if ($Stat){
  $tmp = New-Object System.Object
  $tmp | Add-Member -type NoteProperty -name DisplayName -value $($stat.DisplayName)
  $tmp | Add-Member -type NoteProperty -name Email -value $email
  $tmp | Add-Member -type NoteProperty -name TotalSize_MB -value $($stat.TotalitemSize.value.ToMB())
  $tmp | Add-Member -type NoteProperty -name LastLogon -value $($stat.LastLogonTime)
  $Report += $tmp
 }
}
$Report | Export-Csv D:\Scripts\lastlogon_report.csv

 

As a result of this script, you will get .csv file, with informations DisplayName, email address, size of mailbox in MB, and last logon time.

 

 

Exchange 2010 last logon time to mailbox

 

Sometimes we need to find when user logged to mailbox for the last time.

To achieve this we need to use  Get-MailboxStatistics CMDlet

Below command will display LastLogonTime for mailbox JSmith:

Get-MailboxStatistics JSmith | select DisplayName, LastLogonTime

 

If we are using shared mailboxes we also should display user account which were used to log to mailbox.
This command will display mailbox name, LastLogonTime and user account used to logon:

Get-MailboxStatistics JSmith | select DisplayName, LastLogonTime, LastLoggedOnUserAccount

 

When we want to get logon time information for all mailboxes in database or in mailbox server MX01, we need to use Get-Mailbox CMDlet, and pipe result to Get-MailboxStatistics

Continue reading