Forum Discussion
Using PowerShell to talk to the Office 365 Service Communications API
Attached is the Spreadsheet I created based on the messages I retrieved via the script. I think this is something companies will want to do weekly as part of their Office 365 governance process.
Here's an improved version of the PowerShell. It still uses the old API however. This version is better because it includes the message body and adds columns for GovernanceResponse and Notes to the CSV. You still have to open it in Excel and format it as a table.
$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=@(2)} | convertto-json).tostring() $events = (invoke-restmethod -contenttype "application/json" -method Post -uri "https://api.admin.microsoftonline.com/shdtenantcommunications.svc/GetEvents" -body $jsonPayload) $outfileName = "C:\temp\Message Center\" + $(get-date).ToString("yyyy-MM-dd") + "-Messages.csv" $FormatedEvents = $events.Events | foreach { $row = new-object PSObject add-member -InputObject $row -MemberType NoteProperty -Name MessageID -Value $_.Id add-member -InputObject $row -MemberType NoteProperty -Name LastUpdatedTime -Value $_.LastUpdatedTime.toString("MM/dd/yyyy h:mm tt") add-member -InputObject $row -MemberType NoteProperty -Name Urgency -Value $_.UrgencyLevel add-member -InputObject $row -MemberType NoteProperty -Name ActionType -Value $_.ActionType add-member -InputObject $row -MemberType NoteProperty -Name Category -Value $_.Category add-member -InputObject $row -MemberType NoteProperty -Name Status -Value $_.Status #is this always null? if ($_.ActionRequiredByDate -eq $null){ add-member -InputObject $row -MemberType NoteProperty -Name ActionRequiredBy -Value "" } else { add-member -InputObject $row -MemberType NoteProperty -Name ActionRequiredBy -Value $_.ActionRequiredByDate.toString("MM/dd/yyyy h:mm tt") } add-member -InputObject $row -MemberType NoteProperty -Name Title -Value $_.Title add-member -InputObject $row -MemberType NoteProperty -Name Message -Value $_.Messages[0].MessageText add-member -InputObject $row -MemberType NoteProperty -Name AdditionalInfo -Value $_.ExternalLink add-member -InputObject $row -MemberType NoteProperty -Name GovernanceResponse -Value "" add-member -InputObject $row -MemberType NoteProperty -Name Notes -Value "" Write-Output $row } $FormatedEvents| export-csv -LiteralPath $outfileName -NoTypeInformation
- Dean_GrossJun 01, 2018Silver Contributor
Michael Blumenthalhave you ever figured out how to use the new API to get the Message Center messages? this has me stumped.
- Jun 01, 2018Also see this discussion about wanting to use Flow for this in the future.
https://powerusers.microsoft.com/t5/Flow-Ideas/Office-365-Admin-Message-Center/idi-p/10489- Dean_GrossJun 01, 2018Silver Contributorhere is my discussion about it https://powerusers.microsoft.com/t5/Building-Flows/Enter-a-valid-uri-error-when-trying-to-get-data-from-Office/m-p/120787#M11734
- Jun 01, 2018I ended up just subscribing to the message center weekly digest and using that as I describe in my blog. https://michaelblumenthal.me/2017/07/office-365-governance-essentials-step-1-review-annotate-and-share-weekly-digest/
You can configure your weekly digest subscription in your Message Center options.- Dean_GrossJun 01, 2018Silver Contributor
Thanks, I have been able to create a Flow that gets the messages, but the filtering does not work (appears to be a bug in either the API or in Flows implementation) so I still get the Incidents, which is not optimal.
I am mystified why something that should be so simple, is not.
- Qais ASSEFJan 16, 2018Copper Contributor
Hello Michael Blumenthal, many thanks for sharing your script with us. Do you have any news about the new API ?