Exchange批量删除邮件

 

Add-PSSnapin microsoft.exchange*


$Subject = '警惕“退税”钓鱼邮件' #如果主题中包含&符号等特殊字符,则使用三对单引号
$From = "it@yx.com"
$Sent = "05/09/2023"
$Search = "Sent>=$Sent AND From:$From AND Subject:$Subject"
$KQLQuery=[scriptblock]::create($Search)
$TargetMailbox = "liu@yx.com"
$TargetFolder = "Search"
$DelUser = "p@yx.com"

#仅查找
Search-Mailbox -Identity $DelUser -SearchQuery $KQLQuery -EstimateResultOnly #仅统计数量和大小
 Search-Mailbox -Identity $DelUser -SearchQuery $KQLQuery -LogOnly -TargetMailbox $TargetMailbox -TargetFolder $TargetFolder 
#删除
Search-Mailbox -Identity $DelUser -SearchQuery $KQLQuery -DeleteContent -Force
#查找全员邮箱并进行删除
Get-Mailbox |Search-Mailbox -SearchQuery $KQLQuery -DeleteContent -Force
Get-Mailbox -OrganizationalUnit "$ou" |Search-Mailbox  -SearchQuery $KQLQuery -DeleteContent -Force #查找某个OU下邮箱并进行删除

 

posted on 2023-05-10 17:28  momingliu11  阅读(194)  评论(0编辑  收藏  举报