Solved

PowerShell for Exchange

Posted on 2014-01-20
7
696 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 69

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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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 69

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
To show how to create a transport rule 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 >> Rules tab.:  To cr…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

830 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