Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

migrated from Feb 26 '10 at 18:01

This question came from our site for professional and enthusiast programmers.

You might want to ask this on 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.

share|improve this answer
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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.