Syntax error

Rising Flight 3,771 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

Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,217 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,372 questions
0 comments No comments
{count} votes

Accepted answer
  1. KyleXu-MSFT 26,211 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,211 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.