Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PowerShell for Exchange

Posted on 2014-01-20
7
Medium Priority
?
765 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 

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

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

Question has a verified solution.

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

Unified and professional email signatures help maintain a consistent company brand image to the outside world. This article shows how to create an email signature in Exchange Server 2010 using a transport rule and how to overcome native limitations …
How to deal with a specific error when using the Enable-RemoteMailbox cmdlet to create a mailbox in the cloud-based service, for an existing user in an on-premises Active Directory.
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

715 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