window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-108815698-1');

Exchange Search Query – Sending data to a remote command failed

By |2017-12-07T10:16:28+00:00April 8th, 2015|Exchange|0 Comments

I had to run a hefty search query for a customer today, searching all mailboxes but every time I tried my command it would error:

Get-Mailbox -ResultSize Unlimited | Search-Mailbox -SearchQuery “((sent:(01/03/2015..09/04/2015)) AND (‘SEARCHTERM1’ OR ‘SEARCHTERM2’ OR ‘ SEARCHTERM3’ OR ‘ SEARCHTERM4’ OR ‘ SEARCHTERM5’ OR ‘ SEARCHTERM6’ OR ‘ SEARCHTERM7’))” -TargetMailbox <MailboxForSearchResults> –TargetFolder SearchRequest-08-04-2015 -loglevel Full

After a bit of searching it seems it’s a syntax error, because we cant search so many mailboxes at once you need to collect all the mailboxes into an array then run the search command on each one:

$Mailboxes = Get-Mailbox -ResultSize Unlimited
Foreach ($Mailbox in $Mailboxes) {
Search-Mailbox -identity $Mailbox -SearchQuery “((sent:(01/03/2015..09/04/2015)) AND (‘SEARCHTERM1’ OR ‘SEARCHTERM2’ OR ‘ SEARCHTERM3’ OR ‘ SEARCHTERM4’ OR ‘ SEARCHTERM5’ OR ‘SEARCHTERM6’ OR ‘ SEARCHTERM7’))-TargetMailbox <MailboxForSearchResults> -TargetFolder SearchRequest-08-04-2015 -loglevel Full
}

 

After that it started searching and bringing back results.

 

Hope it help!

Leave A Comment

like what you see? 

Sign-up to our newsletter and never miss out on the latest blogs, events and tech news from the world of risual
SUBSCRIBE!
Give it a try, you can unsubscribe anytime.
I consent to this website use of cookies and third party services. Accept