Share via

systax error

Glenn Maxwell 13,761 Reputation points
2022-04-13T23:13:49.553+00:00

Hi All

i am executing the below syntax and i am getting error. experts guide me

$mailboxes = Import-Csv c:\temp\users.csv
foreach($mailbox in $mailboxes)
Search-Mailbox -Identity $mailbox.Name -SearchQuery {kind:meetings AND From:"******@contos.com" AND Subject:"Test1 + Test2" AND (received>="03/03/2022 00:00" AND received<="03/04/2022 23:59")} -DeleteContent -Force
}

At line:2 char:32

  • foreach($mailbox in $mailboxes)
  • ~
    Missing statement body in foreach loop.
    At line:5 char:1
  • }
  • ~
    Unexpected token '}' in expression or statement.
  • CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
  • FullyQualifiedErrorId : MissingForeachStatement
Exchange Online
Exchange Online

A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.

Exchange | Exchange Server | Management
Exchange | Exchange Server | Management

The administration and maintenance of Microsoft Exchange Server to ensure secure, reliable, and efficient email and collaboration services across an organization.

Exchange | Hybrid management
Exchange | Hybrid management

The administration of a hybrid deployment that connects on-premises Exchange Server with Exchange Online, enabling seamless integration and centralized control.

0 comments No comments

Answer accepted by question author

Kai Yao 37,791 Reputation points Moderator
2022-04-14T02:08:56.337+00:00

Hi @Glenn Maxwell

The cause is that you are missing a { in this part:

foreach($mailbox in $mailboxes)   
Search-Mailbox -Identity $mailbox.Name  

The whole script should be:

 $mailboxes = Import-Csv c:\temp\users.csv  
 foreach($mailbox in $mailboxes)  
 {  
 Search-Mailbox -Identity $mailbox.Name -SearchQuery {kind:meetings AND From:"******@contos.com" AND Subject:"Test1 + Test2" AND (received>="03/03/2022 00:00" AND received<="03/04/2022 23:59")} -DeleteContent -Force  
 }  

If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.