Link to home
Start Free TrialLog in
Avatar of susnewyork
susnewyorkFlag for United States of America

asked on

search-maillbox exact search criteria

Hello,

I have a basic script that searches all mailboxes on our exchange server. How can I limit the search criteria to an exact match?

Search-Mailbox -SearchQuery 'Subject: "TEST"', 'Body: "Test"' -targetmailbox "jbuzzetta" -targetfolder "inbox" -logonly -loglevel full

Results for test, testify, retest will all show up.

I'd like to see only TEST.
Avatar of David Carr
David Carr
Flag of United States of America image

Check that search is running and has a completed index.  look for Event ID 110 in logs to confirm completion.
Test-ExchangeSearch -Identity user@domain.com

Open in new window

For subject searching syntax should be
Search-Mailbox -SearchQuery subject:"Test" -TargetMailbox Administrator -TargetFolder SearchLogs -LogOnly -LogLevel Full

Open in new window

I think what you are taking is the default behavior for Search-mailbox.. You need to add more condition to narrow down your search..
For example..
Search-Mailbox -Identity subsun -SearchQuery 'from:subsuntest AND sent:6/11/2013 AND Subject:"Test mail"' -TargetMailbox Adminmailbox -TargetFolder SearchLogs -LogOnly -LogLevel Full

Open in new window

Avatar of susnewyork

ASKER

PowerShell can't find exact strings excluding extra string data from the search? That sounds like basic functionality. I'd expect that I'd have to use -like to get the results that subject:"Test" is giving.
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
BTB if you are just trying to export the mails then you can try New-MailboxExportRequest with parameter ContentFilter, it allows you to filter the messages based on subject..

Refer :
http://technet.microsoft.com/en-us/library/ff607299(v=exchg.141).aspx
http://technet.microsoft.com/en-us/library/ff601762(v=exchg.141).aspx