1

trying to create script to delete exchange 2010 mailbox messages.

creating input file in csv format with three headers.

Recipients Subject Sender

with these values:

line1: user1@campus.edu,Somesubject,sender@domain.com  
line2: "user2@campus.edu,user3@campus.edu",Somesubject,sender@domain.com

created this powershell script:

$list = Import-Csv "input.csv"
Foreach ($entry in $list)
{
    If ($entry.Recipients.Contains(","))
    {
        $recipients = $entry.Recipients.Split(",")
        ForEach($recipient in $recipients)
        {
            $search = "Subject:`"" + $entry.Subject + "`" And From:`"" + $entry.Sender + "`" And Sent:5/27/2016"
            Write-Host $search
            Search-Mailbox -identity $Recipients -SearchQuery $search -TargetMailbox "my_mailbox" -TargetFolder "05272016" -LogLevel Full -deletecontent
        }
    }
    Else    
    {
        $search = "Subject:`"" + $entry.Subject + "`" And From:`"" + $entry.Sender + "`" And Sent:5/27/2016"
        Write-Host $search
        Search-Mailbox -identity $entry.Recipients -SearchQuery $search -TargetMailbox "my_mailbox" -TargetFolder "05272016" -LogLevel Full -deletecontent
    }

}

It works with single recipients but not multiple recipients. Any ideas how to split multiple recipients.

  • found my problem, changed Search-Mailbox -identity $Recipients to $Recipient in first portion. Thanks for your consideration. – E. Knight May 27 '16 at 21:19
1

found my problem, changed Search-Mailbox -identity $Recipients to $Recipient in first portion. Thanks for your consideration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.