Exchange Powershell Potpourri

Purpose:

The purpose of this article is to display a set of commonly used Exchange Powershell Scripts

Get all email sent to aol in the last 12 hours. Helpfull for locating spam or newsletters
Get-ExchangeServer | Where-Object {$_.IsMailboxServer -eq $true} | Get-MessageTrackingLog -ResultSize unlimited -Start (Get-Date).AddHours(-12) | Where-Object {$_.recipients -like "*@aol.com"} | Select {$_.Recipients}, * | Export-Csv -Path C:\temp\aol.csv
Get the Number of Mailbox Items in a folder in Outlook. Will prompt for identity
Get-MailboxFolderStatistics | Select Name, ItemsInFolder
Get all messages from an address over the last 48 hours. Capped at 5000 messages
Get-MessageTrace -PageSize 5000 -SenderAddress "Sender@blah.com" -Start (Get-Date).AddHours(-48) -EndDate Get-Date | Export-Csv -Path C:\temp\MyExport.csv
Connect to O365 then search detailed mailbox audit logs for a time frame. Operations that are audited by default :updateinboxrules, Movetodeleteditems, softdelete, harddelete and update
Search-MailboxAuditLog -Identity email@domain.com -Showdetails -StartDate 12/14/2020 -EndDate 12/15/2020 -ResultSize 2000 | Export-Csv -Path C:\temp\filename.csv