Delete Content from a specific Folder Exchange 2010

Hi Everyone.

I'm trying to create a script that will delete the content of a specific SubFolder from a specific Mailbox using powershell (EWS is NOT an option at this point)

I came up with the following script:
Get-Mailbox -Identity "" |Search-Mailbox -TargetFolder "Inbox\Bla\Blu\test" -T
argetMailbox "" -DeleteContent -Force

Open in new window

While it does delete the content of the required folder, it also deletes the content of the containing folders (The content of the entire Tree was deleted)!

Obviously this isn't good for us.
I also tried the script with the exact name without the entire tree :
Get-Mailbox -Identity "" |Search-Mailbox -TargetFolder "test" -T
argetMailbox "" -DeleteContent -Force

Open in new window

With the same results.

Any ideas?
David SankovskySenior SysAdminAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jason CrawfordTransport NinjaCommented:

"The TargetFolder parameter specifies a folder name in which search results are saved in the target mailbox. The folder is created in the target mailbox upon execution."

The TargetFolder parameter in the Search-Mailbox cmdlet is pointing to the discovery search mailbox (if you were running the cmdlet to perform a discovery instead of deleting content).  You cannot specify a folder in the source mailbox, only queries using Advanced Query Syntax.  Note you also must be a member of the Discovery Management Role Group.
Jason CrawfordTransport NinjaCommented:
It should look something like this:

Get-Mailbox | Search-Mailbox -SearchQuery {Insert AQS query here} -DeleteContent

You may have to actually specify a TargetMailbox and TargetFolder even though you're not sending the results anywhere for the cmdlet to complete.  The last time I had to do this the HR manager sent out an email to the entire company containing salary info, and I was asked to remove that email from every mailbox in the organization.  It's really based more on message content than folder hierarchy so you may have to find a header value or some other aspect of the email contained in your test folder you can query against.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David SankovskySenior SysAdminAuthor Commented:
Thank you both for answering, while It didn't exactly solve my issue, it did allow me to find a work around.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.