PowerShell to query Intune Health Dashboard

A couple of months ago, we moved the Intune health status data from the http://status.manage.microsoft.com dashboard into the Office 365 Health Dashboard.

We believe the experience is much better, having health information targeted at your tenants region and wrapped up into the overall Office 365 portal.

image

It also means we can use the Microsoft Online API’s to query the health status.

To start, I’ve ripped off some code from my old colleague, Cam Murray. Shout out to his blog, and here’s the post.

https://blogs.technet.microsoft.com/cammurray/2014/09/23/using-powershell-to-obtain-your-tenants-office365-health-dashboard/

His post explains in detail, but essentially we’re connecting using our Intune admin credentials and receiving ALL of the Office 365 health status.

I’ve then added a couple of lines that do the status filtering to only Intune, and some basic formatting to make it readable.

$cred = get-credential
$jsonPayload = (@{userName=$cred.username;password=$cred.GetNetworkCredential().password;} | convertto-json).tostring()
$cookie = (invoke-restmethod -contenttype "application/json" -method Post -uri "https://api.admin.microsoftonline.com/shdtenantcommunications.svc/Register" -body $jsonPayload).RegistrationCookie
$jsonPayload = (@{lastCookie=$cookie;locale="en-US";preferredEventTypes=@(0,1)} | convertto-json).tostring()
$events = (invoke-restmethod -contenttype "application/json" -method Post -uri "https://api.admin.microsoftonline.com/shdtenantcommunications.svc/GetEvents" -body $jsonPayload)

$intuneEvents = $events.Events | ?{$_.AffectedServiceHealthStatus.InternalName -eq 'Intune'}
$intuneEvents | Select-Object -ExpandProperty Messages -ErrorAction SilentlyContinue | Format-Table -Wrap Status, PublishedTime, MessageText

The output will look something like this

image

You could of course then use this info to pipe into your monitoring solution (such as SCOM) or even set the script as a scheduled task to send you an email when there are outages.

Hope this helps, and thanks to Cam for doing all the heavy lifting!

Matt Shadbolt
Senior Program Manager
Enterprise Client and Mobility – Intune