Entra / Microsoft 365 · Compliance & audit
Get service alerts (Graph)
Retrieve Microsoft 365 service health alerts using the Microsoft Graph Security API and report active issues.
Connect & set up
Run these once per session. All scopes are read-only unless the script makes changes.
Connect-MgGraph -Scopes SecurityEvents.Read.All -NoWelcome
Run it
The main script. Copy it, or download the .ps1 and run it from your console.
Connect-MgGraph -Scopes SecurityEvents.Read.All -NoWelcome[array]$Alerts = Get-MgSecurityAlert -All -PageSize 999If (!$Alerts) {Write-Host "No security found"Break}$Report = [System.Collections.Generic.List[Object]]::new()ForEach ($Alert in $Alerts) {$ExtraInfo = $NullSwitch ($Alert.Title) {"Email messages containing phish URLs removed after delivery" {$User = $Alert.UserStates.UserPrincipalName[1]}"User restricted from sending email" {$User = $Alert.UserStates.UserPrincipalName}"Data Governance Activity Policy" {$User = "N/A"}"Admin Submission Result Completed" {$User = $Alert.UserStates.UserPrincipalName[0]$ExtraInfo = "Email from " + $Alert.UserStates.UserPrincipalName[1] + " reported for " + $Alert.UserStates.UserPrincipalName[2]}Default {$User = $Alert.UserStates.userPrincipalName}} # End SwitchIf ([string]::IsNullOrEmpty($Alert.Description)) {$AlertDescription = "Office 365 alert"} Else {$AlertDescription = $Alert.Description}# Unpack comments[String]$AlertComments = $Null; $i = 0ForEach ($Comment in $Alert.Comments) {If ($i -eq 0) {$AlertComments = $Comment; $i++} Else {$AlertComments = $AlertComments + "; " + $Comment}}Switch ($Alert.Status) {"newAlert" { $Color = "ff0000" }"inProgress" { $Color = "ffff00" }"Default" { $Color = "00cc00" }}$ReportLine = [PSCustomObject][Ordered]@{Title = $Alert.TitleCategory = $Alert.CategoryUser = $UserDescription = $AlertDescriptionDate = Get-Date($Alert.EventDateTime) -format gStatus = $Alert.StatusSeverity = $Alert.SeverityViewAlert = $Alert.SourceMaterials[0]Comments = $AlertCommentsExtraInfo = $ExtraInfoColor = $Color}$Report.Add($ReportLine)} # End ForEach$Report | Out-GridView -Title "Office 365 Security Alerts" -PassThru
Attribution
Author
Office365itpros