Solved

powershell script to query and delete emails

Posted on 2016-10-18
8
34 Views
Last Modified: 2016-11-09
Is there a Powershell script to query and delete emails by subject? If someone sends a bad email to a multiple large distribution group i like to search and remove based on subject.
0
Comment
Question by:CiscoAzn
  • 4
  • 4
8 Comments
 
LVL 49

Expert Comment

by:Akhater
ID: 41848659
if you are talking about exchange 2010 and newer here is what you want
https://technet.microsoft.com/en-us/library/ff459253(v=exchg.160).aspx

make sure to pick the exchange version corresponding to the one you have
0
 

Author Comment

by:CiscoAzn
ID: 41848663
This is for Exchange 2010. The link you sent me is for Exchange 2016.
0
 
LVL 49

Expert Comment

by:Akhater
ID: 41848670
:) this is for all exchange versions, just pick the one you want on top of the article

anyway here you go https://technet.microsoft.com/en-us/library/ff459253(v=exchg.141).aspx

2016-10-18-19_53_12-Use-Mailbox-Sear.png
0
 

Author Comment

by:CiscoAzn
ID: 41848801
In the Exchange 2010 version it only shows the search for a mailbox not for the entire org and that's what i'm looking for.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 49

Expert Comment

by:Akhater
ID: 41848826
It is the same thing

Get-Mailbox | search-mailbox -deletecontent

Will do it for all mailboxes
0
 

Author Comment

by:CiscoAzn
ID: 41849525
Thanks Akhater but how do you get a count of the total emails that it query and the total emails that it found before deleting it?
0
 
LVL 49

Accepted Solution

by:
Akhater earned 500 total points
ID: 41849544
If you run the same command with -TargetFolder  -TargetMailbox parameters instead of the deletecontent you will know exactly which emails are going to be deleted


or you can run a simulation with the -DeleteContent with the -WhatIf parameter
0
 

Author Closing Comment

by:CiscoAzn
ID: 41881234
Sorry for the late response but thank you for your assistance.
0

Featured Post

Free book by J.Peter Bruzzese, Microsoft MVP

Are you using Office 365? Trying to set up email signatures but you’re struggling with transport rules and connectors? Let renowned Microsoft MVP J.Peter Bruzzese show you how in this exclusive e-book on Office 365 email signatures. Better yet, it’s free!

Join & Write a Comment

Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
In this video we show how to create a Contact in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Contact ta…
In this video we show how to create an Accepted Domain in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Ac…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now