Have you ever been in a situation whereby a client, friend, colleague, Executives etc. sends or receives and email and all of the sudden, the world comes to an end and you need to remove those emails. Today, I would like to run through some commands which can aid you in this emergency situation. I am sure many out know how to run tracking logs. But running certain criteria matching can be time consuming and in an emergency situation, you will need to match criteria quickly. Imagine an email being forwarded in the queues with 100’s if not 1000’s of users. Then you have a really big issue. Therefore, we will run through some commands with common searches which you may require on the spot.
Let us look at some basic commands:
Search-Mailbox -Identity User@domain.com -SearchQuery ‘Subject:” Example of subject line”‘ –DeleteContent
Search-Mailbox -Identity *@domain.com -SearchQuery ‘Subject:”Example of subject line”‘ –DeleteContent
Very Large Domain Level:
Get-Mailbox *@domain.com –ResultSize Unlimited | Search-Mailbox -SearchQuery ‘Subject:”Example of subject line”‘ –DeleteContent
Now to run against single or multiple criteria’s you need to amend the SearchQuery. And knowing what parameters can be searched is the key. These parameters are tied to Message properties and search operators for In-Place eDiscovery. Here are some of the parameters (Search Operators):
|Property||Property description||Examples||Search results returned by the examples|
|Attachment||The names of files attached to an email message.||
Messages that have an attached file named annualreport.ppt. |
In the second example, using the wildcard returns messages with the word “annual” in the file name of an attachment.
|Bcc||The BCC field of an email message.1||
|All examples return messages with Pilar Pinilla included in the Bcc field.|
The categories to search. Categories can be defined by users by using
Outlook or Outlook Web App. The possible values are: |
|category:”Red Category”||Messages that have been assigned the red category in the source mailboxes.|
|Cc||The CC field of an email message.1||
|In both examples, messages with Pilar Pinilla specified in the CC field.|
|From||The sender of an email message.1||
|Messages sent by the specified user or sent from a specified domain.|
|Importance||The importance of an email message, which a sender can specify when sending a message. By default, messages are sent with normal importance, unless the sender sets the importance as high or low.||
|Messages that are marked as high importance, medium importance, or low importance.|
The message type to search. Possible values: |
kind:email OR kind:im OR kind:voicemail
|Email messages that meet the search criteria. The second example returns email messages, instant messaging conversations, and voice messages that meet the search criteria.|
|Participants||All the people fields in an email message; these fields are From, To, CC, and BCC.1||
Messages sent by or sent to firstname.lastname@example.org. |
The second example returns all messages sent by or sent to a user in the contoso.com domain.
|Received||The date that an email message was received by a recipient.||
received>=01/01/2014 AND received<=03/31/2014
|Messages that were received on April 15, 2014. The second example returns all messages received between January 1, 2014 and March 31, 2014.|
|Recipients||All recipient fields in an email message; these fields are To, CC, and BCC.1||
Messages sent to email@example.com. |
The second example returns messages sent to any recipient in the contoso.com domain.
|Sent||The date that an email message was sent by the sender.||
sent>=06/01/2014 AND sent<=07/01/2014
|Messages that were sent on the specified date or sent within the specified date range.|
|Size||The size of an item, in bytes.||
Messages larger than 25 MB. |
The second example returns messages from 1 through 1,048,576 bytes (1 MB) in size.
|Subject||The text in the subject line of an email message.||
subject:”Quarterly Financials” |
Messages that contain the exact phrase “Quarterly
Financials” anywhere in the text of the subject line. |
The second example returns all messages that contain the word northwind in the subject line.
|To||The To field of an email message.1||
|All examples return messages where Ann Beebe is specified in the To: line.|
To reference more items, can be found in a deep dive article on the Microsoft. Article
However, here are some key searches which the above combining the a basic Search Query, this can be done quickly.
Search-Mailbox -Identity User@domain.com -SearchQuery From:firstname.lastname@example.org –DeleteContent
Search-Mailbox -Identity *@domain.com -SearchQuery From:email@example.com –DeleteContent
Very Large Domain Level:
Get-Mailbox *@domain.com –ResultSize Unlimited | Search-Mailbox -SearchQuery From:firstname.lastname@example.org –DeleteContent
This should help you with a combination of Excel to quick write up some fancy queries and keep the mailboxes clean.