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