Skip to content

Instantly share code, notes, and snippets.

@rdtechie
Created April 3, 2016 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdtechie/45232e0345420c85fe96c780f3c461ac to your computer and use it in GitHub Desktop.
Save rdtechie/45232e0345420c85fe96c780f3c461ac to your computer and use it in GitHub Desktop.
#requires -Version 2
#requires -PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
$xDays = 90
Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox |
ForEach-Object -Process {
$MailboxStats = Get-MailboxStatistics -Identity $_.DistinguishedName
$si = Get-MailboxFolderStatistics -Identity $_.DistinguishedName -IncludeOldestAndNewestItems -FolderScope SentItems
if($si.NewestItemReceivedDate -AND (New-TimeSpan -Start $si.NewestItemReceivedDate.ToLocalTime()).Days -ge $xDays) {
New-Object -TypeName PSObject -Property @{
Name = $_.Name
Alias = $_.Alias
PrimarySmtpAddress = $_.PrimarySmtpAddress
WhenCreated = $_.WhenCreated
Database = $_.Database
LastSentItemDate = $si.NewestItemReceivedDate
LastLogonTime = $si.LastLogonTime
MailboxSize = $MailboxStats.totalitemsize.Value.ToMB()
}
}
} |
Select-Object -Property Name, Alias, PrimarySmtpAddress, LastSentItemDate, WhenCreated, LastLogonTime, Database |
Sort-Object -Property LastSentItemDate |
Export-Csv -Path C:\temp\Inactive90Days.csv -NoTypeInformation -UseCulture
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment