Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PowerShell for Exchange

Posted on 2014-01-20
7
Medium Priority
?
783 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 1000 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 71

Accepted Solution

by:
Qlemo earned 1000 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

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 71

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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
On September 18, Experts Exchange launched the first installment of the Help Bell, a new feature for Premium Members, Team Accounts, and Qualified Experts. The Help Bell will serve as an additional tool to help teams increase question visibility.
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…
In this video we show how to create an email address policy 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…
Suggested Courses

971 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