Search-Mailbox Item Count Zero

The goal is to export monthly content to pst and then delete content from journaling mailboxes for a given date range.  I have found a very handy powershell script to do all of this, however the delete content step does not work.  

 This step in the script is what is failing:  

$endDate = Get-Date -Day 1 "00:00:00"
$startDate = $endDate.AddMonths(-1)
$month = "{0:D2}" -f [int]$startDate.Month

# Convert dates to short date strings
$endDate = $endDate.ToShortDateString()
$startDate = $startDate.ToShortDateString()

Get-Mailbox -Identity "intjournal.mailbox" | Search-Mailbox -SearchQuery "Received:'${startDate}'..'${endDate}'" -DeleteContent

I have added to the Exchange Admin role group 'Organization Management' the 'Mailbox Search' and the 'Mailbox Import Export' roles to this group, of which my user object is a member.  

I can even try a manual search and deletecontent by simply running this:  ( which fails to return anything but '0' in the 'ResultItemsCount' field)

  Search-Mailbox -Identity intjournal.mailbox -SearchQuery "Received:02/01/2015..02/28/2015" -deletecontent -force

Everything I have read today indicates that this script should work.  Am I missing a management role assignment on my user object that is preventing the search from finding / deleting messages?   Is there something different about a journaling mailbox that requires special parameters?   Any help here would be great, I hate having to add more disk space while I figure this out!

Thanks In Advance,

Chris J.


May 8th, 2015 3:16pm

Hi,

I guess the user has missed discovery management permission

Add-RoleGroupMember -Identity "Discovery Management" -Member username

Free Windows Admin Tool Kit Click here and download it now
May 8th, 2015 5:08pm

Already a member of that rolegroup, thanks ManU.  
May 8th, 2015 5:27pm

Hi,

We can use the following command to check if your account is assigned proper permissions to search and delete messages.

Get-ManagementRoleAssignment -Role "Mailbox Import Export"

Get-RoleGroupMember "Discovery Management"

I test the same simple command to search and delete message, it works fine. So there is no problem this that command, and there is no special parameters about a journaling mailbox because the type of journaling mailbox is user mailbox.

Please login this Journal mailbox to check if there are messages during 02/01/2015..02/28/2015.

Best Regards.

Free Windows Admin Tool Kit Click here and download it now
May 11th, 2015 3:13am

Hi Lynn,

  Yes, my user is listed as having this role.  I am still unable to delete messages via the search-mailbox cmdlet, that i referenced in the original post.  ResultItemsCount still shows 0 and the mailbox does still contain items between 02/01/2015 and 02/28/2015.   Perhaps I have the date syntax wrong?  

May 11th, 2015 1:59pm

Hi,

How many items between 02/01/2015 and 02/28/2015 in journal mailbox?

Please test if you can remove the message in that data range by using subject query.

Search-Mailbox journal -SearchQuery 'Subject:"Subject in your message"' DeleteContent

If not, these messages should be corrupted.

If yes, there may be something wrong with date syntax. If so, we can change the date syntax to test it.

Search-mailbox journal -SearchQuery "Received:> $('02/01/2015') and Received:< $('02/28/2015')" -DeleteContent

Best Regards.

Free Windows Admin Tool Kit Click here and download it now
May 11th, 2015 9:50pm

Hi Lynn,

    I get the same result when doing a -SearchQuery by subject.  0 count in ResultItemsCount.

    I went into the journal mailbox, Identified one email with a unique subject that was spam.  The subject name is '[JUNK] RE:VMC Capitol Business Funding'  

   I then went to powershell and issued this command:   'search-mailbox -identity "journal.mailbox" -SearchQuery 'Subject:"[JUNK] RE:VMC Capitol Business Funding"' -DeleteContent.

  

  It still feels like I'm missing something permissions wise.   Why else would my search return 0 items?

May 13th, 2015 12:26pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics