Delete emails from mailbox - Exchange 2010 SP2

adaniel93475
adaniel93475 used Ask the Experts™
on
Anyone know what the right syntax in Powershell is to delete emails based on date or even subject?
i have tried:
get-mailbox -id "arun daniel" | Search-Mailbox -SearchQuery subject:"Your bank statement" -DeleteContent

I end up getting: The target mailbox or .pst file path is required
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hello,

You want to run:

Search-Mailbox -Identity "arun daniel" -SearchQuery subject:"Your bank statement" -DeleteContent

-JJ

Author

Commented:
JJ

Yeah, i tried that as well but i get this:
[PS] C:\Windows\system32>Search-Mailbox -Identity "arun daniel" -SearchQuery subject:"Your bank statement" -DeleteContent
A positional parameter cannot be found that accepts argument '-DeleteContent'.
    + CategoryInfo          : InvalidArgument: (:) [Search-Mailbox], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Search-Mailbox

[PS] C:\Windows\system32>

From my readings, it looks like -DeleteContent is no longer available for SP2?
Sorry, I cut and pasted your powershell without looking closely. You have the quotes wrong.

It should be:

Search-Mailbox -Identity "arun daniel" -SearchQuery "subject:'Your bank statement'" -DeleteContent

-JJ

Author

Commented:
Thanks JJ! other than my fat fingers, i just found out that i have to run that on the source mailbox server (as opposed to the CAS server i always do my work on).

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial