码迷,mamicode.com
首页 > 系统相关 > 详细

【O365 PowerShell Script】隔离邮件报告

时间:2020-08-03 18:41:58      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:receive   form   code   epo   pow   pen   app   com   protect   

#O365的隔离报告https://protection.office.com/quarantine 可以在365的网址上拿到,但是却无法导出,以下脚本可以将隔离的邮件导出,并使用while循环解决单条命令的1000个数据的限制

#O365‘s quarantine report https://protection.office.com/quarantine can be obtained on the 365 website, but it cannot be exported. The following script can export the quarantined emails and use the while loop to solve the 1000 data of a single command limits

#No need to modify any line
#无需更改以下任何一行
#=====================================================

$output = @() 
$ExportCSV= Read-Host "Export the quarantine CSV file location (E.g c:\temp\QuarantineReport.CSV)"  
$StartDate = Get-Date (Read-Host -Prompt ‘Enter the start date, Eg.  08/31/2019‘) 
$StartDate = $StartDate.tostring("MM/dd/yyyy")
$endDate =  Get-Date (Read-Host -Prompt ‘Enter the end date, Eg.  09/30/2019‘)
$endDate = $endDate.tostring("MM/dd/yyyy")

if($ExportCSV -eq "")
{
    $ExportCSV = "c:\temp\QuarantineReport.CSV"
}

If(($StartDate -eq "") -or ($endDate -eq ""))
{
    $Reports = get-quarantinemessage -PageSize 1000

}else{

$page = 1

while (get-quarantinemessage -StartReceivedDate $StartDate -EndReceivedDate $endDate -PageSize 1000 -page $page) 
{
$reports = get-quarantinemessage -StartReceivedDate $StartDate -EndReceivedDate $endDate -PageSize 1000 -page $page
$page++

Foreach($report in $reports)
    {

        $userObj = New-Object PSObject  
        $userObj | Add-Member NoteProperty -Name "Received" -Value $report.ReceivedTime
        $userObj | Add-Member NoteProperty -Name "Sender" -Value $report.SenderAddress
        $userObj | Add-Member NoteProperty -Name "Subject" -Value $report.Subject
        $UserObj | Add-Member NoteProperty -Name "Recipient" -Value $report.RecipientAddress
        $userObj | Add-Member NoteProperty -Name "Quarantine reason" -Value $report.QuarantineTypes
        $userObj | Add-Member NoteProperty -Name "Released?" -Value $report.Released
        $userObj | Add-Member NoteProperty -Name "Policy Type" -Value $report.PolicyType
        $userObj | Add-Member NoteProperty -Name "Message ID" -Value $report.MessageId
        $userObj | Add-Member NoteProperty -Name "Expires" -Value $report.Expires

        $output += $UserObj  
    }

    $output | Export-csv $ExportCSV -Encoding UTF8 -NoTypeInformation -append
    Write-host ("CSV file page " + ($page-1) + " has been exported to " + $ExportCSV)  -fore Green 

}
}

Write-host ("================================================================================")
Write-host ("CSV file has been exported to " + $ExportCSV)  -fore Green 

}

}

【O365 PowerShell Script】隔离邮件报告

标签:receive   form   code   epo   pow   pen   app   com   protect   

原文地址:https://blog.51cto.com/12954151/2516144

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!