power shell exchange filter Deleted Items

Hello!!
I’m just looking for some PowerShell help on exchange. What I am trying to find out is who have more than 1,000 items in their deleted folder in outlook.
I can find out the sizes of the deleted items folder with:

$mailFrom = "housekeeping@...."
$mailto = "tes@..."
$smtpServer = "mail.??.local"
$warninglimit = 1000
Write-Host "warninglimit: $($warninglimit) " -ForegroundColor Green
Get-MailboxStatistics -server EX1 | ft displayName,deletedItemCount,@{l="TotalDeletedItemSize";e={$_.totalDeletedItemSize.value.toMB()}}

 I then need to be able to filter the result from there.

-Filter { DeletedItemCount -ge $warninglimit }

I’m just unsure how to put this all together!

The reason for this is eventually it will be an automated script (once a week) that e-mails users who have more than 1,000 items and recommending that they clear out their deleted folder. Then once this is under control I will implement a exchange policy that automatically cleans up their deleted items on their behalf.

Thank you !



stephenHenderson123Asked:
Who is Participating?
 
MNH1966Connect With a Mentor Commented:
Don't have an Exchange server handy to test right now, but this should get you in the right direction:

Get-Mailbox | Get-MailboxFolderStatistics -folderscope 'Deleted Items' | Where-Object ($_.ItemsInFolder -gt 1000) | ft displayName,deletedItemCount
0
 
AkhaterConnect With a Mentor Commented:
here you go
$mailFrom = "housekeeping@...."
$mailto = "tes@..."
$smtpServer = "mail.??.local"
$warninglimit = 100
Write-Host "warninglimit: $($warninglimit) " -ForegroundColor Green
Get-MailboxStatistics -server ex1 | ? {$_.DeletedItemCount -gt $warninglimit} | ft displayName,deletedItemCount,@{l="TotalDeletedItemSize";e={$_.totalDeletedItemSize.value.toMB()}}

Open in new window

0
 
stephenHenderson123Author Commented:
Superb thank you

i will post the whole script once complete, might be useful to someone in the future !!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.