Hi Slava,
This would give me the users who last accessed their mailbox, not the amount and size of emails older than 180 days including those who still access their mailboxes.
I think I figured out a way though. I have written the following scripts which seem to work..
To create new mailbox searches, one for each DB.. (uncomment the first two lines if ran from Exchange shell)
#Import-Module "C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1"
#Connect-ExchangeServer exchangeserverFQDN
$endDate=(get-date).adddays(-180)
$DBs = Get-MailboxDatabase -IncludePreExchange2013
foreach ($DB in $DBs) {
$mailboxes = Get-Mailbox -Database $DB
New-MailboxSearch -name $DB.name -SourceMailboxes $mailboxes -EndDate $endDate -EstimateOnly
Start-MailboxSearch $DB.name
}
And then I have to monitor completion using Get-MailboxSearch. Once all of them are completed, I can run the following script to export the data to a CSV.. I have yet to run it to confirm as the first script hasn't completed it's first run..
#Import-Module "C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1"
#Connect-ExchangeServer exchangeserverFQDN
$file = oldEmails.csv
$mailboxSearch = Get-MailboxSearch | Select-Object Name,NumberMailboxToSearch,ResultNumberEstimate,ResultSizeEstimate.toGB()
$append = $false
foreach ($search in $mailboxSearch) {
if ($append -eq $false) {
$search | Export-Csv $file
$append = $true
}
else {
$search | Export-Csv $file -Append
}
}
I'll update once I confirm that both of the scripts work well.
-
Edited by
mdeschenes
17 hours 50 minutes ago
clarifications & typo
-
Proposed as answer by
Amit TankMVP, Moderator
8 hours 20 minutes ago