Solved

PowerShell for Exchange

Posted on 2014-01-20
7
673 Views
Last Modified: 2014-01-26
Need to remove a particular message from all users in the current database. Currently, we are doing this one by one. Is it possible to modify the below script to automate this process, by importing a csv file with all the email that need to remove a particular message ? Tks


Search-Mailbox -Identity "jo.leung" -SearchQuery 'Subject:Backup Exec Alert and received:12/25/2014' –DeleteContent
0
Comment
Question by:AXISHK
  • 3
  • 2
7 Comments
 
LVL 25

Assisted Solution

by:Zephyr ICT
Zephyr ICT earned 250 total points
ID: 39796197
What's the Exchange version?

Does something like this not give the wanted result?

get-mailbox -resultsize unlimited | Search-Mailbox -SearchQuery 'Subject:Backup Exec Alert and received:12/25/2014' –DeleteContent
0
 

Author Comment

by:AXISHK
ID: 39796276
Is it possible to limited the searching within a special time range ?

Tks
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 250 total points
ID: 39796967
I take it you definitive do NOT want to delete the content of all mailboxes, only for specific ones contained in the CSV.
get-content C:\Temp\Mailboxes.txt | Search-Mailbox -Identity $_ -SearchQuery 'Subject:Backup Exec Alert AND received:>12/25/2013 AND received:<1/1/2014' –DeleteContent -WhatIf

Open in new window

0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:AXISHK
ID: 39798910
Doesn't work. Any idea ?

[PS] C:\Windows\system32>Search-Mailbox -Identity "John.leung" -SearchQuery "received:>01/21/2014 AND received:<01/2
2/2014" –Logonly –Targetmailbox buadmin –Targetfolder Inbox
Try using fewer keywords at the same time, reducing the number of users in the From, To, Cc, and Bcc fields, and reduci
ng the number of mailboxes that are searched at the same time. When you use wildcards, make search queries as specific
as possible. For example, if the search query used short words with one or more wildcards (for example, pat*), a large
number of words or phrases may be returned because all words that start with "pat" are searched. Search failed on mailb
ox 'abc\John M H Leung\682601b5-50f9-458d-a7da-d6dd62f4470c'.
    + CategoryInfo          : ReadError: (0:Int32) [Search-Mailbox], SearchMailboxException
    + FullyQualifiedErrorId : BB69DE3C,Microsoft.Exchange.Management.Tasks.SearchMailbox



RunspaceId       : f1d4a044-6eea-4bd2-a6f3-35e68abb652f
Identity         : abc.com.hk/HK//John Leung
DisplayName      : John Leung
TargetMailbox    : abc.com.hk/SERVERS/HK/Users/BUadmin
TargetPSTFile    :
Success          : False
TargetFolder     : \Inbox\
ResultItemsCount : 0
ResultItemsSize  : 0 B (0 bytes)
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 39799324
No idea, since that works for me without error (but without result either - cannot test that far).
0
 

Author Closing Comment

by:AXISHK
ID: 39810866
The following powershell works for me, thanks for the information.

Search-Mailbox -Identity "John.lo" -SearchQuery {received:01/24/2014 9:00 ..01/24/2014 10:00}  –Logonly –Targetmailbox itadmin –Targetfolder Inbox
0

Featured Post

Don't lose your head updating email signatures!

Do your end users still have the wrong email signature? Do email signature updates bore you or fill you with a sense of dread? You can make this a whole lot easier on yourself by trusting an Exclaimer email signature management solution. Over 50 million users do...so should you!

Join & Write a Comment

Resolve DNS query failed errors for Exchange
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
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 Address List 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 Organization >> Ad…

758 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

17 Experts available now in Live!

Get 1:1 Help Now