<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Cam Murray PFE</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/cammurray/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/cammurray/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 03:22:48 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Using PowerShell to obtain your Tenants Office365 Health Dashboard</title>
      <link>https://docs.microsoft.com/archive/blogs/cammurray/using-powershell-to-obtain-your-tenants-office365-health-dashboard</link>
      <pubDate>Tue, 23 Sep 2014 21:26:00 GMT</pubDate>
      <dc:creator><![CDATA[Cameron_Murray]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/cammurray/2014/09/23/using-powershell-to-obtain-your-tenants-office365-health-dashboard/</guid>
      <description><![CDATA[Obtaining the Office 365 Health Status via script has become a lot easier now with the release of...]]></description>
      <content:encoded><![CDATA[<p>Obtaining the Office 365 Health Status via script has become a lot easier now with the release of the Office 365 Service Communications API. An overview of the Office 365 Service Communications API and the methods can be found on MSDN at the following URL:&nbsp;<a href="https://msdn.microsoft.com/en-us/library/office/dn776043(v=office.15).aspx">https://msdn.microsoft.com/en-us/library/office/dn776043(v=office.15).aspx</a></p>
<p>Because the API is a standard JSON based web api we can leverage in-built functionality in PowerShell 4.0 to convert our request to/from JSON and invoke the API. The PowerShell commands i&#39;ll be using in this blog article are the ConvertTo-JSON (for converting our request to JSON format) and the Invoke-RestMethod (for invoking the API itself).</p>
<p>First off, we need to obtain our credentials which we will use for the initial registration.</p>
<p style="margin-left:30px;"><span style="color:#ff6600;">$cred</span> = <span style="color:#0000ff;">get-credential</span></p>
<p>We now need to obtain our authentication cookie by calling the Register method with our&nbsp;Office 365 username&nbsp;and password.&nbsp;The&nbsp;Register method will return a cookie which can be used to authenticate subsequent requests for up to 2 days. Each additional method will return an updated Cookie, which extends the life of the cookie for another 48 hours.</p>
<p>The Service URL as per the MSDN documentation is&nbsp;&quot;https://api.admin.microsoftonline.com/shdtenantcommunications.svc/&quot;. The Method that we are calling to obtain the cookie&nbsp;is the Register method.. To call this method, we add the method name to the URL, so that it is &quot;https://api.admin.microsoftonline.com/shdtenantcommunications.svc/Register&quot;. We then invoke the web request with our username and password in JSON format. The method will return several properties, one of which is our RegistrationCookie. We need to store this cookie for future API requests.</p>
<p style="margin-left:30px;"><span style="color:#ff6600;">$jsonPayload</span> = (@{userName=<span style="color:#ff6600;">$cred</span>.username;password=<span style="color:#ff6600;">$cred</span>.GetNetworkCredential().password;} | <span style="color:#0000ff;">convertto-json</span>).tostring()</p>
<p style="margin-left:30px;"><span style="color:#ff6600;">$cookie</span> = (<span style="color:#0000ff;">invoke-restmethod</span><span style="color:#000080;"> -contenttype</span><span style="color:#993366;"> &quot;application/json&quot;</span> <span style="color:#000080;">-method</span> <span style="color:#cc99ff;">Post</span> -uri <span style="color:#993366;">&quot;https://api.admin.microsoftonline.com/shdtenantcommunications.svc/Register&quot;</span> <span style="color:#000080;">-body</span><span style="color:#ff6600;"> $jsonPayload</span>).RegistrationCookie</p>
<p>The cookie above can be stored&nbsp;as an alternative in storing your username &amp; password credentials.&nbsp;You can use the cookie to authenticate to the API for future requests without having to call the Register method again. The cookie is only valid for 48-hours, but a new cookie is provided every time a method is ran on the API, theoretically making it possible never to have&nbsp;to use the actual Office 365 credentials more than once.</p>
<p>Now comes the fun part, we can call any of the methods with our cookie and obtain information from the dashboard. For this example, i&#39;m going to use the GetEvents method to show all current Office 365 events. This method has a preferredEventTypes parameter which allows us to select which type of events to return. In this example, i&#39;m going to use both the event types 0 and 1, which are for Service Incidents and Maintenance Events.</p>
<p style="margin-left:30px;"><span style="color:#ff6600;">$jsonPayload</span> = (@{lastCookie=<span style="color:#ff6600;">$cookie</span>;locale=&quot;en-US&quot;;preferredEventTypes=@(0,1)} | convertto-json).tostring()<br /><span style="color:#ff6600;">$events</span> = (<span style="color:#0000ff;">invoke-restmethod</span> -contenttype <span style="color:#993366;">&quot;application/json&quot;</span><span style="color:#000080;"> -method</span> <span style="color:#cc99ff;">Post</span><span style="color:#000080;"> -uri</span> <span style="color:#993366;">&quot;https://api.admin.microsoftonline.com/shdtenantcommunications.svc/GetEvents&quot;</span> <span style="color:#000080;">-body</span> <span style="color:#ff6600;">$jsonPayload</span>)</p>
<p>Now, let&#39;s inspect what&#39;s returned..</p>
<p style="margin-left:30px;"><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/03/44/Events%20GetMember.PNG" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-44/Events-GetMember.PNG"><img alt=" " src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/03/44/Events%20GetMember.PNG" original-url="https://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-44/Events-GetMember.PNG" border="0" /></a></p>
<p style="margin-left:30px;"></p>
<p>The &quot;<strong>LastCookie</strong>&quot; is updated with a fresh new cookie which we can use for future authentication requests. It is valid for another 2 days. This is what we can use for theoretically never having to re-run the Register method as this cookie can be used for future authentication.</p>
<p>The &quot;<strong>Events&quot;&nbsp;</strong>is a property array of the events returned, lets inspect:</p>
<p style="margin-left:30px;"><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/03/44/Events.Events%20GetMember.PNG" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-44/Events.Events-GetMember.PNG"><img alt=" " src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/03/44/Events.Events%20GetMember.PNG" original-url="https://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-44/Events.Events-GetMember.PNG" border="0" /></a></p>
<p>Here we have the main request. In here we have entries for the start and end time of the event, messages, and status and title of the event. The &quot;<strong>AffectedServiceHealthStatus</strong>&quot; is another property, which includes the effected service name for the event. Below is an example of one of the events returned:</p>
<p style="margin-left:30px;"><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/03/44/ReturnedEvent.PNG" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-44/ReturnedEvent.PNG"><img alt=" " src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/03/44/ReturnedEvent.PNG" original-url="https://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-44/ReturnedEvent.PNG" border="0" /></a></p>
<p>As you can see, polling the API is relatively easy to achieve with in-built commands for web API&#39;s in PowerShell 4.0. For full documentation on the Service API, visit MSDN:&nbsp;<a href="https://msdn.microsoft.com/en-us/library/office/dn776043(v=office.15).aspx">https://msdn.microsoft.com/en-us/library/office/dn776043(v=office.15).aspx</a></p>
<p></p>]]></content:encoded>
    </item>
  </channel>
</rss>