Avatar of dougdog
dougdog
 asked on

whats the command to delete an email from all mailboxes in exchange 2007 sp2

i need to delete an email from every mailbox
NetworkingExchangePowershell

Avatar of undefined
Last Comment
Hendrik Wiese

8/22/2022 - Mon
Hendrik Wiese

Export and delete all messages that contain "TEST Subject" in their subject from all mailboxes from the DB1 database to a folder called "TEST DATA" in the Administrator mailbox:

Get-mailbox -database 'DB1' | export-mailbox –SubjectKeywords "TEST Subject" -TargetFolder "TEST DATA" -TargetMailbox Administrator –DeleteContent 

Open in new window


And ensure that you have the correct permission as per the following article: http://www.kevintaber.com/2009/06/09/search-for-and-delete-emails-in-exchange-2007-mailboxes-using-powershell/

Hope this helps!!
Rajkumar Duraisamy

Same as above mentioned command, To search it from all the mailbox and you dont want to have a backup of those emails

Get-mailbox -ResultSize unlimited| export-mailbox –SubjectKeywords "TEST Subject" –DeleteContent
dougdog

ASKER
is it meant to move all the emails with test subject to a folder in the specified mailbox
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Hendrik Wiese

Yes that is what it does and after it moved all the messages it will delete them. ;)
dougdog

ASKER
can i get it to not delete them id rather do it manually im afraid of this deleting more data that its mean to
dougdog

ASKER
i was going to use this command its the only one i can seem to get working

Get-Mailbox -Server EXCHSVR01 | Export-Mailbox -SubjectKeywords “Confidential reports” -StartDate “06/09/2009¿ -DeleteContent
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Hendrik Wiese

Then run the command like this to move it to the administrator mailbox

Get-mailbox -database 'DB1' | export-mailbox –SubjectKeywords "TEST Subject" -TargetFolder "TEST DATA" -TargetMailbox Administrator
dougdog

ASKER
can i have it to run against the server as i have multiple databases
Hendrik Wiese

Try the following:

Get-mailbox -ResultSize unlimited | export-mailbox –SubjectKeywords "TEST Subject" -TargetFolder "TEST DATA" -TargetMailbox Administrator
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
dougdog

ASKER
when i run thsi the folder i created remains empty
dougdog

ASKER
when i run this command it looks like it is deleting loads of mail
im a little worried its deleting more than i t should
Capture.PNG
dougdog

ASKER
and the test data folder remain empty
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Hendrik Wiese

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.