How to Use the AND Operator in Exchange Search-Mailbox
Question details
The user needs to construct a valid search query using the AND operator in Exchange 2013 Search-Mailbox to filter emails by both subject and sent date.

- Product
- Microsoft Exchange Server 2013
- Device & OS
- not provided
- Scenario
- Filtering messages within an on-premises Exchange 2013 environment based on multiple criteria (subject and sent date).
- Observed behavior
- Exchange 2013 Search-Mailbox queries fail or return inaccurate results when attempting to combine subject and sent date filters using the AND operator.
Ensure you have the 'Mailbox Import Export' management role assigned to your administrator account, as this is required to run the Search-Mailbox cmdlet.
Use Correct KQL Syntax for the SearchQuery Parameter
The -SearchQuery parameter relies on Keyword Query Language (KQL), not standard PowerShell operators. The AND operator must be capitalized and properly formatted.
A common mistake when using Search-Mailbox is attempting to use the PowerShell '-and' operator inside the query string. KQL requires operators like AND, OR, and NOT to be strictly uppercase.
Additionally, ensure that dates are formatted correctly according to your server's regional settings, or use standard formatting like MM/DD/YYYY.
Launch the Exchange Management Shell (EMS) on your Exchange 2013 server as an administrator.
Construct your query using uppercase AND. For example, to search for a subject and a date range: 'Subject:"Project Update" AND Sent:"01/01/2013..12/31/2013"'
Run the complete command. Example: Search-Mailbox -Identity "UserAlias" -SearchQuery 'Subject:"Project Update" AND Sent:"01/01/2013..12/31/2013"' -TargetMailbox "DiscoveryMailbox" -TargetFolder "SearchFolder"

Consult the Exchange Server Administration Forum
If standard KQL syntax still results in failures, the issue may stem from your specific on-premises index configurations or catalog health.
Enhance Your Productivity with WPS Office
While resolving on-premises Microsoft Exchange server queries requires specialized tools like the Exchange Management Shell, handling the resulting reports, exported data, and daily communications is easier with WPS Office. WPS Office is a powerful, lightweight suite that serves as an excellent alternative to Microsoft Office.
- 1. Download the Installer: Visit the official WPS Office website and click the free download button.
- 2. Install WPS Office: Run the downloaded installer and follow the quick on-screen instructions.
- 3. Open Your Files: Launch WPS Office to easily open your existing Microsoft Word, Excel, or PowerPoint files without formatting loss.

Frequently Asked Questions
Why does my Search-Mailbox query return an invalid syntax error?
This usually occurs if you use standard PowerShell operators (like -and) instead of Keyword Query Language (KQL) operators. Always use a capitalized 'AND' inside the SearchQuery string.
Do I need special permissions to run the Search-Mailbox cmdlet?
Yes, you must be assigned the 'Mailbox Import Export' management role. By default, this role is not assigned to any administrator group in Exchange 2013 and must be added manually.
Can I use multiple AND operators in a single Exchange search query?
Yes, you can chain multiple conditions using AND, OR, and NOT operators in KQL, provided you format them in uppercase and use proper quotation marks for phrases.
How do I format the date for the Sent parameter in a KQL query?
Date formats generally depend on the regional settings of the Exchange server, but using the format 'MM/DD/YYYY' or 'YYYY-MM-DD' is recommended. You can specify a date range using two dots, for example: '01/01/2013..12/31/2013'.




