M365 Powershell

Microsoft 365: Spam Report of last 10 days

August 19, 2020

author:

Microsoft 365: Spam Report of last 10 days

Sometimes it’s useful to have a fast export of the spam report over the last 10 days for example. Also here powershell is the way to go.

#requires -version 2
<#
.SYNOPSIS
  Get Spam Report
.DESCRIPTION
  Get Spam Report
.NOTES
  Version:        1.0
  Author:         Pascal Briner
  Creation Date:  14.04.2020
  Purpose/Change: 
#>

#---------------------------------------------------------[Initialisations]--------------------------------------------------------

#---------------------------------------------------------[Authentication]--------------------------------------------------------
# run scripts in authentication folder
#----------------------------------------------------------[Declarations]----------------------------------------------------------
$ExportFilePath = "C:\temp\"
$date = get-date -format "yyyy-MM-dd-HH-mm"
$file = ("Log_getSpamReport_" + $date + ".csv")
$ExportFile = $ExportFilePath + "\" + $file

$StartDate = (get-date).AddDays(-10) 
$EndDate = Get-Date 



#-----------------------------------------------------------[Functions]------------------------------------------------------------


#-----------------------------------------------------------[Execution]------------------------------------------------------------
Get-MailDetailSpamReport -StartDate $StartDate -EndDate $EndDate | Export-CSV $ExportFile -NoTypeInformation -Encoding utf8
Invoke-Item $ExportFile

You need to be authenticated against EXO.

Leave a comment