Get-Office365ServiceAPIStatus.ps1
<#PSScriptInfo
.VERSION 1.0 .GUID cfaf3efa-2fc5-4727-bac5-7149d6a69956 .DESCRIPTION Query the Office 365 Service Communications API. .AUTHOR Aaron Guilmette .COMPANYNAME Microsoft .COPYRIGHT 2021 .TAGS ServiceComms Office365 API .LICENSEURI .PROJECTURI https://www.undocumented-features.com/2021/03/16/office-365-service-communications-api-powershell-script/ .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES #> <# .SYNOPSIS Query Office 365 status .PARAMETER TenantID The Tenant ID of your Office 365 instance. .PARAMETER ClientID Use the App Registration ID. .PARAMETER ClientSecret Use the client secret you create as part of the app registration. .PARAMETER RequestType Select which type of request to issue: - CurrentStatus: Current status of Office 365 services (default) - Services: Services currently in your subscription - HistoricalStatus: Historical service status - Messages: Data from the message center .PARAMETER Count Indicates how many Messages or HistoricalStatus items to return. .NOTES 2021-03-16 - Initial release .LINK https://www.undocumented-features.com/2021/03/16/office-365-service-communications-api-powershell-script/ #> param ( $TenantId, $ClientId, $ClientSecret, [ValidateSet('Services', 'CurrentStatus', 'HistoricalStatus', 'Messages')]$RequestType = "CurrentStatus", $Count = 20 # Number of messages or status items to go back ) # OAuth Token Endpoint $uri = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" # Construct Body for OAuth Token $body = @{ client_id = $ClientId scope = "https://manage.office.com/.default" client_secret = $ClientSecret grant_type = "client_credentials" } # Get Token $TokenRequest = try { Invoke-RestMethod -Method Post -Uri $uri -ContentType "application/x-www-form-urlencoded" -Body $body -ErrorAction Stop } catch [System.Net.WebException] { Write-Warning "Exception was caught: $($_.Exception.Message)" } If ($TokenRequest) { $token = $TokenRequest.access_token } Else { "No token detected. Ending."; Break } # Get Office 365 Service Communication Status $Results = try { Invoke-RestMethod -Method Get -Uri "https://manage.office.com/api/v1.0/$tenantid/ServiceComms/$RequestType" -ContentType "application/json" -Headers @{ Authorization = "Bearer $token" } -ErrorAction Stop } catch [System.Net.WebException] { Write-Warning "Exception: $($_.Exception.Message)" } # List API results switch ($RequestType) { Services { $Results.Value | Format-Table @{ L = "Service Name"; E = { "$($_.DisplayName) ($($_.Id))" } }, @{ L = "Features"; E = { $_.Features.DisplayName -join ", " } } } CurrentStatus { $Results.Value | % { $_.FeatureStatus | Select-Object FeatureDisplayName, FeatureServiceStatusDisplayName } } HistoricalStatus { $Results.Value[0 .. ($Count - 1)] | Format-Table StatusTime, WorkloadDisplayName, StatusDisplayName, IncidentIds } Messages { $Results.Value[0 .. ($Count - 1)] | Format-Table Title, Workload, StartTime, Endtime, Severity, MessageType, ImpactDescription } } |