0

I know there are a number of similar questions on here. I've scoured them all. I've tried enclosing various parts of the code in quotes and in parentheses, a couple of solutions that worked in similar other topics. None worked and I still don't know how to correct the issue I'm facing. The problem code is identified as being in line 24 of the script, which is the line that begins $SearchResults = and the plus signs (+) are obviously the issue.

Any ideas? TIA!

# Search all mailboxes
$mailboxes = Get-Mailbox -ResultSize Unlimited
foreach ($mailbox in $mailboxes) {
    foreach ($filename in $filenames) {
        $searchResults = Search-Mailbox -Identity $mailbox.Identity -SearchQuery 'attachment:"' + $filename + '"' -EstimateResultOnly
        if ($searchResults.ResultItemsCount -gt 0) {
            $results += New-Object PSObject -Property @{
                Location = $mailbox.Identity
                Filename = $filename
                Count = $searchResults.ResultItemsCount
ChopOMatic
  • 47
  • 2
  • 6
  • 2
    need parens here: `-SearchQuery ('attachment:"' + $filename + '"')` otherwise `Search-Mailbox` thinks you're trying to pass that stuff as argument of other parameters ;) – Santiago Squarzon May 04 '23 at 21:13
  • 2
    `-SearchQuery ('attachment:"' + $filename + '"')` or `-SearchQuery ('attachment:"{0}"' -f $filename)` – Theo May 04 '23 at 21:16
  • Huge thanks. The script is actually running now, albeit with an unending stream of WARNING: On July 1, 2020, blah yada yada... – ChopOMatic May 04 '23 at 21:58

0 Answers0