Search Mailboxes by Date

Had a requirement to search mailboxes by a specific date. In our case it was to look at the size of a mailbox if looking at the last 6 months. Here is something close, which will search for mail receive by a specific date.


# variables
param (
$path = "C:\temp\output.csv",
$exchangeURI = "http://ExchangeServer/PowerShell/",
$exchangeSession = "ExchangeServer"
)
# function to connect to exchange Server
Function ExchangeConnect
{
If ($Session.ComputerName -like $exchangeSession){
Write-Host "Session already established to exchange" -ForegroundColor Green
}
Else {
Write-Host "Session not made to exchange, creating session now" -ForegroundColor Red
$UserCredential = Get-Credential
$Session = New-PSSession `
-ConfigurationName Microsoft.Exchange `
-ConnectionUri $exchangeURI `
-Authentication Kerberos `
-Credential $UserCredential
Import-PSSession $Session
}
}
# Need to create a Function to Populate a list of users to $List
Function PopulateList {
}
# function to search mailboxes and get size by date range
Function SearchMailboxes {
ForEach ($user in $List){
Search-Mailbox `
-Identity $user `
-SearchQuery "Received:> $('01/01/2017') and Received:< $('08/23/2017')" `
-EstimateResultOnly | `
Export-CSV $path
}
}
# Script Main Body
ExchangeConnect
PopulateList
SearchMailboxes

I did not populate the function that gets the $List of users. This can be done with a simple search of mailboxes or a CSV import of users you want to search. I will write-up something on that if I need to.

Bookmark the permalink.

Comments are closed.