<# IOP Service Health Export International Office Products, https://iop.com.pk/service-credit-check/ What it does Reads your Microsoft 365 Service Health history (incidents and advisories) and saves it as a CSV file that the Service Credit Check page can read. It only reads. It changes nothing in your tenant and sends nothing to IOP. You upload the file yourself, and the page reads it in your browser. What you need - Windows PowerShell 5.1 or PowerShell 7 - The Microsoft Graph PowerShell modules (the script offers to install them for you, for your account only) - A Microsoft 365 account that can read Service Health, such as a Global Reader, Service Support Administrator or Helpdesk Administrator. At sign-in Microsoft asks you to allow "ServiceHealth.Read.All" (read service health). How to run it 1. Save this file, for example to your Downloads folder. 2. Open PowerShell, go to that folder and run: .\IOP-ServiceHealth-Export.ps1 (If Windows blocks it: Unblock-File .\IOP-ServiceHealth-Export.ps1, then run it again.) 3. Sign in when the Microsoft window opens. 4. The CSV is saved in the same folder. Upload it on the Service Credit Check page. Options -Days 90 how far back to look (default 60; Microsoft keeps a limited history) -OutFile where to save the CSV #> [CmdletBinding()] param( [ValidateRange(1, 365)][int]$Days = 60, [string]$OutFile = (Join-Path -Path (Get-Location) -ChildPath ("M365_ServiceHealth_{0}.csv" -f (Get-Date -Format 'yyyy-MM-dd'))) ) $ErrorActionPreference = 'Stop' foreach ($m in 'Microsoft.Graph.Authentication', 'Microsoft.Graph.Devices.ServiceAnnouncement') { if (-not (Get-Module -ListAvailable -Name $m)) { $answer = Read-Host "The module $m is needed. Install it for your account now? (Y/N)" if ($answer -notmatch '^[Yy]') { Write-Host 'Stopped. Nothing was changed.'; return } Install-Module -Name $m -Scope CurrentUser -Force -AllowClobber } Import-Module $m } Connect-MgGraph -Scopes 'ServiceHealth.Read.All' -NoWelcome try { $since = (Get-Date).AddDays(-$Days).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ') $now = Get-Date $issues = Get-MgServiceAnnouncementIssue -Filter "startDateTime ge $since" -All $rows = foreach ($i in ($issues | Sort-Object StartDateTime -Descending)) { $start = ([datetime]$i.StartDateTime).ToLocalTime() $ongoing = -not $i.EndDateTime # no end time yet: still open $end = if ($ongoing) { $now } else { ([datetime]$i.EndDateTime).ToLocalTime() } $span = $end - $start [pscustomobject][ordered]@{ IncidentID = $i.Id Service = $i.Service Classification = [string]$i.Classification Status = [string]$i.Status AffectedTime_Local = $start.ToString('yyyy-MM-dd HH:mm:ss') RestoreTime_Local = if ($ongoing) { 'Ongoing' } else { $end.ToString('yyyy-MM-dd HH:mm:ss') } Duration_Local = '{0}d {1:00}h {2:00}m' -f $span.Days, $span.Hours, $span.Minutes Total_Minutes = [int][math]::Round($span.TotalMinutes) Title = $i.Title Description = ($i.ImpactDescription -replace "`r`n|`n", ' ') } } $rows | Export-Csv -Path $OutFile -NoTypeInformation -Encoding UTF8 Write-Host ("Saved {0} entries to {1}" -f @($rows).Count, $OutFile) Write-Host 'Upload this file on https://iop.com.pk/service-credit-check/' } finally { Disconnect-MgGraph | Out-Null }