I want to delete a certain group of messages from somebody's mailbox. I already have the basic Powershell command ready to go:

Get-Mailbox -Identity jshmoe | Export-Mailbox -SubjectKeywords "VirusWarning" -IncludeFolders "\Inbox" -StartDate "02/24/2010" -DeleteContent

The problem is that Joe Shmoe's "Inbox" is huge, and I know the messages I want to delete are only in the main Inbox folder. However, the above Powershell command appears to crawl all subfolders beneath "Inbox". Is there a way to tell it not to?

  • You might want to ask this on ServerFault.com since it's more SysAdmin related.
    – Joe Doyle
    Feb 26 '10 at 17:59

You need the -IncludeFolders parameter, look at the examples here. Be aware that you may need to specify the folder name in the different languages your users may be using, e.g. -IncludeFolders "\Inbox","\Bandeja de Entrada" for English+Spanish.

  • link is dead "here"
    – Dani
    Feb 26 '15 at 19:00

looks like this was intended behaviour, but a workaround is shown here

essentially you build a variable containing a list of the folders you want to exclude...

$r = [regex]'/';
$exclude = Get-Mailbox -Identity jshmoe | Get-MailboxFolderStatistics | where {$_.folderpath -ne "/" -and $_.FolderPath -ne "/Inbox"} | Select-Object FolderPath | Foreach {$_.folderpath.tostring()} | foreach {$r.replace($_”,”\”,-1)}

then build up your typical Export-Mailbox command with an exclude instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy