Syntax error

Rising Flight 6,176 Reputation points
2020-08-21T02:27:59.45+00:00

Hi i am using the below syntax to delete an email from 3 user mailboxes with subject Test've Test-abcdef msggg, i have csv file in the below format. i am getting syntax error.

Name
user1@Company portal .com
user2@Company portal .com
user3@Company portal .com

$mailboxes = Import-Csv C:/temp/mailboxes.csv
ForEach ($mailbox in $mailboxes){
New-ComplianceSearch -Name $mailbox.name -ExchangeLocation $mailbox.name -ContentMatchQuery '(Received:08/18/2020 00:00..08/20/2020 23:59) AND (Subject:"Test've Test-abcdef msggg") AND (From:"anon@USER ")'
Start-ComplianceSearch -Identity $mailbox.name
}

New-ComplianceSearch -Name $mailbox.name, is it possible to give any name for compliance search, if i use $mailbox.name will the name of compliancesearch be user1@Company portal .comuser2@Company portal .comuser3@Company portal .com

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.
0 comments No comments
{count} votes

Answer accepted by question author
  1. KyleXu-MSFT 26,396 Reputation points
    2020-08-25T05:29:01.863+00:00

    >Missing closing '}' in statement block

    As it said, there missing a "}" for ForEach function.


    If the response is helpful, please click "Accept Answer" and upvote it.


2 additional answers

Sort by: Most helpful
  1. Edward van Biljon 1 Reputation point
    2020-08-21T06:11:12.193+00:00

    Hi

    Maybe instead of Import-Csv C:/temp/mailboxes.csv, change the / with \ :

    Import-Csv "C:\temp\mailboxes.csv"

    0 comments No comments

  2. KyleXu-MSFT 26,396 Reputation points
    2020-08-24T02:47:08.773+00:00

    >is it possible to give any name for compliance search

    You need to modify the source file as below:
    19773-snipaste-2020-08-24-10-46-23.png

    Then modify this part in that script:
    19783-snipaste-2020-08-24-10-42-23.png

    Before running script each time, you also need to modify the SearchName(such as from S1,2,3 to a1,2,3), otherwise, it will still conflict(error like: this Compliance Search name exists)


    If the response is helpful, please click "Accept Answer" and upvote it.


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.