Exchange 2010 get list of mailboxes with logon time information

This post is also available in: Polish

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.

 

 

Print Friendly
Tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>