尝试创建脚本来删除 Exchange 2010 邮箱消息。
创建具有三个标题的 csv 格式的输入文件。
收件人 主题 发件人
具有以下值:
line1: [email protected],Somesubject,[email protected]
line2: "[email protected],[email protected]",Somesubject,[email protected]
创建了这个 powershell 脚本:
$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
}
}
它适用于单个收件人,但不适用于多个收件人。有没有什么办法可以拆分多个收件人。
答案1
发现了我的问题,在第一部分中将 Search-Mailbox -identity $Recipients 更改为 $Recipient。感谢您的考虑。