How to use Office 365 Service Communications API V2 with PowerShell

%3CLINGO-SUB%20id%3D%22lingo-sub-253417%22%20slang%3D%22en-US%22%3EHow%20to%20use%20Office%20365%20Service%20Communications%20API%20V2%20with%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-253417%22%20slang%3D%22en-US%22%3E%3CP%3EJust%20today%2C%20when%20I%20ran%20this%20code%20to%20connect%20to%20the%20Office%20365%20Service%20API.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F49928iBF989E5BDC58ABD3%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22powershell_2018-09-17_20-06-16.png%22%20title%3D%22powershell_2018-09-17_20-06-16.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20looks%20like%20the%20API%20Service%20EndPoint%20is%20down%2C%20and%20I'm%20not%20sure%20if%20this%20is%20tempory%20or%20permanent.%3C%2FP%3E%3CP%3EGot%20me%20thinking%20about%20moving%20to%20to%20the%20v2%20API%20(%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice%2Foffice-365-management-api%2Foffice-365-service-communications-api-reference%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice%2Foffice-365-management-api%2Foffice-365-service-communications-api-reference%3C%2FA%3E).%20I%20was%20able%20to%20go%20through%20registering%20the%20app%20in%20Azure%2C%20but%20the%20way%20it%20is%20handled%20in%20PowerShell%20looks%20way%20different%20than%20that%20of%20the%20v1%20API.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHas%20anyone%20had%20any%20success%20in%20scripting%20with%20the%20v2%20API%20for%20retrieving%20the%20Office%20365%20Service%20Status%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-253417%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-283318%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20use%20Office%20365%20Service%20Communications%20API%20V2%20with%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-283318%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20All%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20sorry%20it%20took%20long%20for%20me%20to%20update%20this.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20published%20a%20working%2C%20functional%20script%20that%20I%20am%20already%20using%20in%20production.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20can%20read%20through%20the%20post%20here%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fwww.lazyexchangeadmin.com%2F2018%2F10%2Fshd365.html%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.lazyexchangeadmin.com%2F2018%2F10%2Fshd365.html%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20hope%20this%20helps.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-278072%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20use%20Office%20365%20Service%20Communications%20API%20V2%20with%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-278072%22%20slang%3D%22en-US%22%3E%3CP%3EBelow%20is%20the%20PowerShell%20script%20I%20came%20up%20with%20which%20uses%20v2%20of%20the%20Graph%20API.%26nbsp%3B%20A%20few%20notes%3A%3C%2FP%3E%3CUL%3E%3CLI%3EYou%20will%20need%20to%20register%20an%20Azure%20app%20for%20use%20with%20this%20script.%26nbsp%3B%20The%20app%20will%20need%20to%20be%20granted%20permissions%20to%20read%20tenant%20health%20info.%26nbsp%3B%20I%20have%20not%20included%20instructions%20for%20registering%20the%20Azure%20app.%26nbsp%3B%20A%20good%20starting%20point%20on%20how%20to%20do%20this%20can%20be%20found%20at%20the%20following%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EURL%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Flazyadmin.nl%2Fit%2Fusing-microsoft-graph-api-with-powershell%2F.%26nbsp%3B%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Flazyadmin.nl%2Fit%2Fusing-microsoft-graph-api-with-powershell%2F.%26nbsp%3B%3C%2FA%3E%3C%2FLI%3E%3CLI%3EReview%20the%20%22script%20variables%22%20section%20of%20the%20script%20and%20adjust%20as%20necessary.%3C%2FLI%3E%3CLI%3EAs%20this%20is%20my%20first%20try%20at%20using%20the%20Graph%20API%2C%20I'm%20not%20convinced%20the%20portion%20of%20the%20code%20which%20retrieves%20the%20OAuth%20token%20is%20optimal.%26nbsp%3B%20Please%20share%20any%20changes%20you%20make%20to%20improve%20that%20portion%20of%20the%20script.%3C%2FLI%3E%3CLI%3EThe%20secret%20for%20the%20registered%20app%20is%20stored%20in%20a%20file%20(location%20specified%20in%20PassFile%20variable).%26nbsp%3B%20For%20the%20version%20of%20the%20script%20we%20use%2C%20we%20encrypt%20PassFile%20and%20have%20the%20script%20decrypt%20it%20in%20order%20to%20retrieve%20the%20secret.%26nbsp%3B%20For%20the%20version%20I've%20attached%20I%20assume%20an%20unencrypted%20file%20is%20used%20to%20store%20the%20secret.%3C%2FLI%3E%3C%2FUL%3E%3CP%3EHopefully%20others%20can%20make%20use%20of%20this%20and%20please%20share%20any%20improvements%20you%20make%20with%20the%20community.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E--------------------------%3C%2FP%3E%3CP%3EMonitor-Tenant-Health%3C%2FP%3E%3CP%3E--------------------------%3CBR%20%2F%3E%23Script%20variables%3CBR%20%2F%3E%24HistoryFile%20%3D%20%22Enter%20folder%20and%20path%20to%20file%20which%20will%20be%20used%20to%20track%20tenant%20health%20history%20(i.e.%20C%3A%5CTemp%5CTenantHealth.csv)%22%3CBR%20%2F%3E%24PassFile%20%3D%20%22Location%20of%20file%20containing%20client%20secret%20for%20Azure%20app%20created%20for%20use%20in%20obtaining%20tenant%20health%22%3CBR%20%2F%3E%24ClientID%20%3D%20%22Application%20ID%20of%20Azure%20app%20created%20for%20use%20in%20obtaining%20tenant%20health%22%3CBR%20%2F%3E%24TenantDomain%20%3D%20%22yourtenant.onmicrosoft.com%22%3CBR%20%2F%3E%24TenantGUID%20%3D%20%22GUID%20of%20your%20tenant%22%3CBR%20%2F%3E%24NotificationRecipients%20%3D%20%40(%22someone%40somewhere.com%22)%3CBR%20%2F%3E%24NotificationSender%20%3D%20%22donotreply%40somewhere.com%22%3CBR%20%2F%3E%24SmtpServer%20%3D%20%22smtpserver.somewhere.com%22%3CBR%20%2F%3E%24SmtpPort%20%3D%20%2225%22%3CBR%20%2F%3E%24RedirectUri%20%3D%20%22https%3A%2F%2Flocalhost%22%3CBR%20%2F%3E%24LoginUrl%20%3D%20%22%3CA%20href%3D%22https%3A%2F%2Flogin.microsoft.com%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Flogin.microsoft.com%3C%2FA%3E%22%3CBR%20%2F%3E%24Resource%20%3D%20%22%3CA%20href%3D%22https%3A%2F%2Fmanage.office.com%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fmanage.office.com%3C%2FA%3E%22%3C%2FP%3E%3CP%3E%23Retrieve%20health%20events%20from%20previous%20run%3CBR%20%2F%3E%24HistoryTable%20%3D%20%40%7B%7D%3CBR%20%2F%3EIf%20(Test-Path%20%24HistoryFile)%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%24HistoryFileContents%20%3D%20Get-Content%20-Path%20%24HistoryFile%3CBR%20%2F%3EForEach%20(%24Entry%20in%20%24HistoryFileContents)%20%7B%24HistoryTable.Add((%24Entry.Split(%22%2C%22))%5B0%5D%2C(%24Entry.Split(%22%2C%22))%5B1%5D)%7D%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3E%23Retrieve%20OAuth%20token%3CBR%20%2F%3E%24ClientSecret%20%3D%20Get-Content%20%24PassFile%3CBR%20%2F%3E%24RequestBody%20%3D%20%40%7Bgrant_type%3D%22client_credentials%22%3Bredirect_uri%3D%24RedirectUri%3Bresource%3D%24Resource%3Bclient_id%3D%24ClientID%3Bclient_secret%3D%24ClientSecret%7D%3CBR%20%2F%3E%24OAuth%20%3D%20Invoke-RestMethod%20-Method%20Post%20-Uri%20%24LoginUrl%2F%24TenantDomain%2Foauth2%2Ftoken%3Fapi-version%3D1.0%20-Body%20%24RequestBody%3CBR%20%2F%3E%24HeaderParams%20%3D%20%40%7B'Authorization'%3D%22%24(%24OAuth.Token_Type)%20%24(%24Oauth.Access_Token)%22%7D%3C%2FP%3E%3CP%3E%23Retrieve%20current%20O365%20health%20events%20posted%20for%20tenant%3CBR%20%2F%3E%24O365Incidents%20%3D%20(Invoke-RestMethod%20-Method%20Get%20-Uri%20%24Resource%2Fapi%2Fv1.0%2F%24TenantGUID%2FServiceComms%2FMessages%20-Headers%20%24HeaderParams).Value%20%7C%20Where%20%7B%24_.MessageType%20-eq%20%22Incident%22%7D%3C%2FP%3E%3CP%3E%23Get%20list%20of%20new%20or%20changed%20events%3CBR%20%2F%3E%24NewChangedEvents%20%3D%20%40()%3CBR%20%2F%3EForEach%20(%24Incident%20in%20%24O365Incidents)%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%24NewChangedFlag%20%3D%200%3CBR%20%2F%3EIf%20(%24HistoryTable.ContainsKey(%24Incident.Id))%3CBR%20%2F%3E%7B%3CBR%20%2F%3EIf%20(%24HistoryTable%5B%24Incident.Id%5D%20-ne%20(Get-Date(%24Incident.LastUpdatedTime)).ToLocalTime().ToString(%22yyyy%2FMM%2Fdd%20HH%3Amm%3Ass%22))%20%7B%24NewChangedFlag%20%3D%201%3B%20%24HistoryTable%5B%24Incident.Id%5D%20%3D%20(Get-Date(%24Incident.LastUpdatedTime)).ToLocalTime().ToString(%22yyyy%2FMM%2Fdd%20HH%3Amm%3Ass%22)%7D%3CBR%20%2F%3E%7D%3CBR%20%2F%3EElse%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%24HistoryTable.Add(%24Incident.Id%2C(Get-Date(%24Incident.LastUpdatedTime)).ToLocalTime().ToString(%22yyyy%2FMM%2Fdd%20HH%3Amm%3Ass%22))%3CBR%20%2F%3E%24NewChangedFlag%20%3D%201%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20(%24NewChangedFlag%20-eq%201)%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%24LatestMessage%20%3D%20%24(%24Incident.Messages%20%7C%20Sort-Object%20-Property%20PublishedTime)%5B%24Incide3nt.Messages.Count%20-%201%5D%3CBR%20%2F%3E%24Event%20%3D%20New-Object%20PSObject%3CBR%20%2F%3E%24Event%20%7C%20Add-Member%20-Type%20NoteProperty%20-Name%20ID%20-Value%20%24Incident.Id%3CBR%20%2F%3E%24Event%20%7C%20Add-Member%20-Type%20NoteProperty%20-Name%20Service%20-Value%20%24Incident.WorkloadDisplayName%3CBR%20%2F%3E%24Event%20%7C%20Add-Member%20-Type%20NoteProperty%20-Name%20Status%20-Value%20%24Incident.Status%3CBR%20%2F%3E%24Event%20%7C%20Add-Member%20-Type%20NoteProperty%20-Name%20StartTime%20-Value%20(Get-Date(%24Incident.StartTime)).ToLocalTime().ToString(%22yyyy%2FMM%2Fdd%20HH%3Amm%3Ass%22)%3CBR%20%2F%3E%24Event%20%7C%20Add-Member%20-Type%20NoteProperty%20-Name%20LastUpdatedTime%20-Value%20(Get-Date(%24Incident.LastUpdatedTime)).ToLocalTime().ToString(%22yyyy%2FMM%2Fdd%20HH%3Amm%3Ass%22)%3CBR%20%2F%3E%24Event%20%7C%20Add-Member%20-Type%20NoteProperty%20-Name%20Details%20-Value%20%24LatestMessage.MessageText%3CBR%20%2F%3E%24Event%20%7C%20Add-Member%20-Type%20NoteProperty%20-Name%20NotificationRecipients%20%24NotificationRecipients%3CBR%20%2F%3E%24NewChangedEvents%20%2B%3D%20%40(%24Event)%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3EForEach%20(%24Event%20in%20%24NewChangedEvents)%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%23Build%20HTML%20for%20email%3CBR%20%2F%3E%24MessageText%20%3D%20%24Event.Details%20-replace(%22%60n%22%2C'%3CBR%20%2F%3E')%20-replace(%5Bchar%5D8217%2C%22'%22)%20-replace(%5Bchar%5D8220%2C'%22')%20-replace(%5Bchar%5D8221%2C'%22')%20-replace('%5C%5B'%2C'%3CB%3E%3CI%3E')%20-replace('%5C%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3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3BH4%7Bfont-size%3A%2012px%3B%20padding-top%3A%204px%3B%7D%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3B%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Blt%3BBR%20%2F%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bgt%3B%24HTML%20%2B%3D%20%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3BTABLE%7Bborder%3A%201px%20solid%20black%3B%20border-collapse%3A%20collapse%3B%20font-size%3A%208pt%3B%20table-layout%3A%20fixed%3B%20width%3A%20800px%3B%7D%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3B%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Blt%3BBR%20%2F%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bgt%3B%24HTML%20%2B%3D%20%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3BTABLE.summary%7Btext-align%3A%20center%3B%20width%3A%20auto%3B%7D%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3B%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Blt%3BBR%20%2F%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bgt%3B%24HTML%20%2B%3D%20%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3BTH%7Bborder%3A%201px%20solid%20black%3B%20background%3A%20%23dddddd%3B%20padding%3A%205px%3B%20color%3A%20%23000000%3B%7D%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3B%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Blt%3BBR%20%2F%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bgt%3B%24HTML%20%2B%3D%20%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3BTD%7Bborder%3A%201px%20solid%20black%3B%20padding%3A%205px%3B%20vertical-align%3A%20top%3B%20%7D%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3B%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Blt%3BBR%20%2F%26amp%3Bamp%3Bamp%3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amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bgt%3B%24HTML%20%2B%3D%20%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3B.firstrunnotice%20%7B%20font-size%3A%2014px%3B%20color%3A%20%234286f4%3B%20%7D%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3B%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Blt%3BBR%20%2F%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bgt%3B%24HTML%20%2B%3D%20%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3B%3C%2FSTYLE%3E%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%3CTABLE%3E%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%3CTBODY%3E%3CTR%20bgcolor%3D%22%26quot%3B%26quot%3B%23000099%26quot%3B%26quot%3B%22%3E%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%20%3CTD%20align%3D%22%26quot%3B%26quot%3Bcenter%26quot%3B%26quot%3B%22%3E%3CFONT%20color%3D%22%26quot%3B%26quot%3B%23ffffff%26quot%3B%26quot%3B%22%3EEvent%20ID%3C%2FFONT%3E%3C%2FTD%3E%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%20%3CTD%20align%3D%22%26quot%3B%26quot%3Bcenter%26quot%3B%26quot%3B%22%3E%3CFONT%20color%3D%22%26quot%3B%26quot%3B%23ffffff%26quot%3B%26quot%3B%22%3EService%3C%2FFONT%3E%3C%2FTD%3E%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%20%3CTD%20align%3D%22%26quot%3B%26quot%3Bcenter%26quot%3B%26quot%3B%22%3E%3CFONT%20color%3D%22%26quot%3B%26quot%3B%23ffffff%26quot%3B%26quot%3B%22%3EStatus%3C%2FFONT%3E%3C%2FTD%3E%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%20%3CTD%20align%3D%22%26quot%3B%26quot%3Bcenter%26quot%3B%26quot%3B%22%3E%3CFONT%20color%3D%22%26quot%3B%26quot%3B%23ffffff%26quot%3B%26quot%3B%22%3EEvent%20Start%20Time%3C%2FFONT%3E%3C%2FTD%3E%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%20%3CTD%20align%3D%22%26quot%3B%26quot%3Bcenter%26quot%3B%26quot%3B%22%3E%3CFONT%20color%3D%22%26quot%3B%26quot%3B%23ffffff%26quot%3B%26quot%3B%22%3ELast%20Updated%3C%2FFONT%3E%3C%2FTD%3E%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%3C%2FTR%3E%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%3CTR%20bgcolor%3D%22%26quot%3B%26quot%3B%230000FF%26quot%3B%26quot%3B%22%3E%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%20%3CTD%20align%3D%22%26quot%3B%26quot%3Bcenter%26quot%3B%26quot%3B%22%3E%3CFONT%20color%3D%22%26quot%3B%26quot%3B%23ffffff%26quot%3B%26quot%3B%22%3E%24(%24Event.ID)%3C%2FFONT%3E%3C%2FTD%3E%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%20%3CTD%20align%3D%22%26quot%3B%26quot%3Bcenter%26quot%3B%26quot%3B%22%3E%3CFONT%20color%3D%22%26quot%3B%26quot%3B%23ffffff%26quot%3B%26quot%3B%22%3E%24(%24Event.Service)%3C%2FFONT%3E%3C%2FTD%3E%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%20%3CTD%20align%3D%22%26quot%3B%26quot%3Bcenter%26quot%3B%26quot%3B%22%3E%3CFONT%20color%3D%22%26quot%3B%26quot%3B%23ffffff%26quot%3B%26quot%3B%22%3E%24(%24Event.Status)%3C%2FFONT%3E%3C%2FTD%3E%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%20%3CTD%20align%3D%22%26quot%3B%26quot%3Bcenter%26quot%3B%26quot%3B%22%3E%3CFONT%20color%3D%22%26quot%3B%26quot%3B%23ffffff%26quot%3B%26quot%3B%22%3E%24(%24Event.StartTime)%3C%2FFONT%3E%3C%2FTD%3E%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%20%3CTD%20align%3D%22%26quot%3B%26quot%3Bcenter%26quot%3B%26quot%3B%22%3E%3CFONT%20color%3D%22%26quot%3B%26quot%3B%23ffffff%26quot%3B%26quot%3B%22%3E%24(%24Event.LastUpdatedTime)%3C%2FFONT%3E%3C%2FTD%3E%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%3C%2FTR%3E%3CTR%3E%3CTD%20colspan%3D%22%26quot%3B%26quot%3B5%26quot%3B%26quot%3B%22%20style%3D%22%26quot%3B%26quot%3Bborder%3Anone%26quot%3B%26quot%3B%22%3E%26amp%3Bnbsp%3B%3C%2FTD%3E%3C%2FTR%3E%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%3CTR%3E%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%20%3CTD%20colspan%3D%22%26quot%3B%26quot%3B5%26quot%3B%26quot%3B%22%3E%24MessageText%3CBR%20%2F%3E%26amp%3Bnbsp%3B%3CBR%20%2F%3E%3CA%20href%3D%22%26quot%3B%26quot%3B%26lt%3BA%22%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fo365health.ad.csbsju.edu%2F%22%22%26gt%3BOffice%3C%2FA%3E%20365%20Health%20Dashboard%3C%2FTD%3E%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%3C%2FTR%3E%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%3CTR%3E%3CTD%20colspan%3D%22%26quot%3B%26quot%3B5%26quot%3B%26quot%3B%22%20style%3D%22%26quot%3B%26quot%3Bborder%3Anone%26quot%3B%26quot%3B%22%3E%26amp%3Bnbsp%3B%3C%2FTD%3E%3C%2FTR%3E%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%3C%2FTBODY%3E%3C%2FTABLE%3E%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%22%3CBR%20%2F%3E%24HTML%20%2B%3D%20%22%22%3C%2FP%3E%3CP%3E%23Send%20notification%3CBR%20%2F%3ESend-MailMessage%20-From%20%24NotificationSender%20-To%20%24NotificationRecipients%20-Subject%20%22O365%20Health%20Alert%20-%20%24(%24Event.Service)%20%5BEvent%20ID%3A%20%24(%24Event.ID)%5D%22%20-Body%20%24HTML%20-BodyAsHtml%20-SmtpServer%20%24SmtpServer%20-Port%20%24SmtpPort%20-UseSsl%3CBR%20%2F%3E%7D%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-277801%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20use%20Office%20365%20Service%20Communications%20API%20V2%20with%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-277801%22%20slang%3D%22en-US%22%3E%3CP%3Ecould%20you%20please%20share%20script%20with%20API%20v2.%20It's%20not%20working%20for%20us.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-253650%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20use%20Office%20365%20Service%20Communications%20API%20V2%20with%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-253650%22%20slang%3D%22en-US%22%3E%3CP%3EFYI%20-%20It%20seems%20like%20the%20older%20API%20endpoint%20is%20back%20up%20again.%26nbsp%3B%20At%20least%20for%20us%20it's%20working.%26nbsp%3B%20However%2C%20we%20do%20plan%20to%20work%20on%20converting%20our%20scripts%20to%20using%20the%20newer%20API.%26nbsp%3B%20Biggest%20hurdle%20for%20us%20was%20just%20registering%20the%20app%20in%20Azure%20and%20figuring%20out%20the%20best%20way%20to%20manage%20the%20authentication%20tokens.%26nbsp%3B%26nbsp%3BThe%20documentation%20is%20definitely%20lacking%2C%20but%20the%20objects%20returned%20from%20the%20API%20seem%20somewhat%20similar%20to%20those%20of%20the%20older%20API.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-253512%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20use%20Office%20365%20Service%20Communications%20API%20V2%20with%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-253512%22%20slang%3D%22en-US%22%3Efigured%20it%20out%2C%20after%20hours%20of%20testing.%20really%20lacking%20documentation.%3CBR%20%2F%3EI%20find%20that%20the%20v2%20API%20filter%20doesn't%20work%2C%20as%20it%20returns%20all%20messages%20to%20your%20rest%20query.%20Although%20this%20is%20no%20big%20deal%20since%20the%20results%20can%20be%20filtered%20for%20consumption%20anyway.%3CBR%20%2F%3E%3CBR%20%2F%3EI'm%20still%20working%20on%20the%20script%2C%20and%20would%20probably%20be%20sharing%20tomorrow.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-253463%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20use%20Office%20365%20Service%20Communications%20API%20V2%20with%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-253463%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20are%20using%20the%20O365ServiceCommunications%20module%20written%20by%20Matt%20McNabb%20(%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmattmcnabb%2FO365ServiceCommunications%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fmattmcnabb%2FO365ServiceCommunications%3C%2FA%3E)%20and%20started%20receiving%26nbsp%3B%22The%20service%20is%20unavailable%22%20messages%20on%209%2F15.%26nbsp%3B%20We%20didn't%20realize%20the%20API%20that%20this%20module%20utilizes%20was%20slated%20to%20be%20deprecated.%26nbsp%3B%20We%20would%20also%20be%20interested%20if%20anyone%20has%20any%20code%20to%20share%20on%20how%20to%20retrieve%20health%20and%20message%20center%20events%20using%20v2%20of%20the%20API.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1153349%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20use%20Office%20365%20Service%20Communications%20API%20V2%20with%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1153349%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F9442%22%20target%3D%22_blank%22%3E%40Shawn%20Beckers%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWe%20are%20using%20almost%20same%20script%20which%20works%20just%20fine%20when%20run%20manually.%20However%2C%20when%20running%20as%20a%20scheduled%20job%2C%20it%20fails%20with%20below%20error.%20Initial%20auth%20token%20call%20is%20successful%20but%20fails%20on%20next%20call%20to%20retrieve%20messages.%20Any%20idea%2Fsuggestions%3F%20Appreciate%20it!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESystem.Net.WebException%3A%20The%20underlying%20connection%20was%20closed%3A%20An%20unexpected%20error%20occurred%20on%20a%20send.%20---%26gt%3B%20System.IO.IOException%3A%20Unable%20to%20read%20data%20from%20the%20transport%20connection%3A%20An%20existing%20connection%20was%20forcibly%20closed%20by%20the%20remote%20host.%20---%26gt%3B%20System.Net.Sockets.SocketException%3A%20An%20existing%20connection%20was%20forcibly%20closed%20by%20the%20remote%20host%3CBR%20%2F%3Eat%20System.Net.Sockets.Socket.EndReceive(IAsyncResult%20asyncResult)%3CBR%20%2F%3Eat%20System.Net.Sockets.NetworkStream.EndRead(IAsyncResult%20asyncResult)%3CBR%20%2F%3E---%20End%20of%20inner%20exception%20stack%20trace%20---%3CBR%20%2F%3Eat%20System.Net.TlsStream.EndWrite(IAsyncResult%20asyncResult)%3CBR%20%2F%3Eat%20System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult%20ar)%3CBR%20%2F%3E---%20End%20of%20inner%20exception%20stack%20trace%20---%3CBR%20%2F%3Eat%20Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest%20request)%3CBR%20%2F%3Eat%20Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1158236%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20use%20Office%20365%20Service%20Communications%20API%20V2%20with%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1158236%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F77943%22%20target%3D%22_blank%22%3E%40Rahul%20Babar%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20believe%20I've%20run%20into%20that%20error%2C%20or%20a%20similar%20one%2C%20when%20connections%20are%20being%20blocked%20by%20firewall%20or%20some%20other%20locally%20running%20security%20app.%26nbsp%3B%20Do%20you%20have%20anything%20like%20that%20running%20on%20this%20machine%3F%26nbsp%3B%20If%20so%2C%20I'd%20suggest%20temporarily%20disabling%20to%20see%20if%20that%20allows%20you%20to%20run%20the%20scheduled%20script.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

Just today, when I ran this code to connect to the Office 365 Service API.

powershell_2018-09-17_20-06-16.png

 

It looks like the API Service EndPoint is down, and I'm not sure if this is tempory or permanent.

Got me thinking about moving to to the v2 API (https://docs.microsoft.com/en-us/office/office-365-management-api/office-365-service-communications-...). I was able to go through registering the app in Azure, but the way it is handled in PowerShell looks way different than that of the v1 API.

 

Has anyone had any success in scripting with the v2 API for retrieving the Office 365 Service Status?

 

 

8 Replies
Highlighted

We are using the O365ServiceCommunications module written by Matt McNabb (https://github.com/mattmcnabb/O365ServiceCommunications) and started receiving "The service is unavailable" messages on 9/15.  We didn't realize the API that this module utilizes was slated to be deprecated.  We would also be interested if anyone has any code to share on how to retrieve health and message center events using v2 of the API.

Highlighted
figured it out, after hours of testing. really lacking documentation.
I find that the v2 API filter doesn't work, as it returns all messages to your rest query. Although this is no big deal since the results can be filtered for consumption anyway.

I'm still working on the script, and would probably be sharing tomorrow.
Highlighted

FYI - It seems like the older API endpoint is back up again.  At least for us it's working.  However, we do plan to work on converting our scripts to using the newer API.  Biggest hurdle for us was just registering the app in Azure and figuring out the best way to manage the authentication tokens.  The documentation is definitely lacking, but the objects returned from the API seem somewhat similar to those of the older API.

Highlighted

could you please share script with API v2. It's not working for us.

Highlighted

Below is the PowerShell script I came up with which uses v2 of the Graph API.  A few notes:

  • You will need to register an Azure app for use with this script.  The app will need to be granted permissions to read tenant health info.  I have not included instructions for registering the Azure app.  A good starting point on how to do this can be found at the following URL: https://lazyadmin.nl/it/using-microsoft-graph-api-with-powershell/. 
  • Review the "script variables" section of the script and adjust as necessary.
  • As this is my first try at using the Graph API, I'm not convinced the portion of the code which retrieves the OAuth token is optimal.  Please share any changes you make to improve that portion of the script.
  • The secret for the registered app is stored in a file (location specified in PassFile variable).  For the version of the script we use, we encrypt PassFile and have the script decrypt it in order to retrieve the secret.  For the version I've attached I assume an unencrypted file is used to store the secret.

Hopefully others can make use of this and please share any improvements you make with the community. 

 

--------------------------

Monitor-Tenant-Health

--------------------------
#Script variables
$HistoryFile = "Enter folder and path to file which will be used to track tenant health history (i.e. C:\Temp\TenantHealth.csv)"
$PassFile = "Location of file containing client secret for Azure app created for use in obtaining tenant health"
$ClientID = "Application ID of Azure app created for use in obtaining tenant health"
$TenantDomain = "yourtenant.onmicrosoft.com"
$TenantGUID = "GUID of your tenant"
$NotificationRecipients = @("someone@somewhere.com")
$NotificationSender = "donotreply@somewhere.com"
$SmtpServer = "smtpserver.somewhere.com"
$SmtpPort = "25"
$RedirectUri = "https://localhost"
$LoginUrl = "https://login.microsoft.com"
$Resource = "https://manage.office.com"

#Retrieve health events from previous run
$HistoryTable = @{}
If (Test-Path $HistoryFile)
{
$HistoryFileContents = Get-Content -Path $HistoryFile
ForEach ($Entry in $HistoryFileContents) {$HistoryTable.Add(($Entry.Split(","))[0],($Entry.Split(","))[1])}
}

#Retrieve OAuth token
$ClientSecret = Get-Content $PassFile
$RequestBody = @{grant_type="client_credentials";redirect_uri=$RedirectUri;resource=$Resource;client_id=$ClientID;client_secret=$ClientSecret}
$OAuth = Invoke-RestMethod -Method Post -Uri $LoginUrl/$TenantDomain/oauth2/token?api-version=1.0 -Body $RequestBody
$HeaderParams = @{'Authorization'="$($OAuth.Token_Type) $($Oauth.Access_Token)"}

#Retrieve current O365 health events posted for tenant
$O365Incidents = (Invoke-RestMethod -Method Get -Uri $Resource/api/v1.0/$TenantGUID/ServiceComms/Messages -Headers $HeaderParams).Value | Where {$_.MessageType -eq "Incident"}

#Get list of new or changed events
$NewChangedEvents = @()
ForEach ($Incident in $O365Incidents)
{
$NewChangedFlag = 0
If ($HistoryTable.ContainsKey($Incident.Id))
{
If ($HistoryTable[$Incident.Id] -ne (Get-Date($Incident.LastUpdatedTime)).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss")) {$NewChangedFlag = 1; $HistoryTable[$Incident.Id] = (Get-Date($Incident.LastUpdatedTime)).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss")}
}
Else
{
$HistoryTable.Add($Incident.Id,(Get-Date($Incident.LastUpdatedTime)).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss"))
$NewChangedFlag = 1
}

If ($NewChangedFlag -eq 1)
{
$LatestMessage = $($Incident.Messages | Sort-Object -Property PublishedTime)[$Incide3nt.Messages.Count - 1]
$Event = New-Object PSObject
$Event | Add-Member -Type NoteProperty -Name ID -Value $Incident.Id
$Event | Add-Member -Type NoteProperty -Name Service -Value $Incident.WorkloadDisplayName
$Event | Add-Member -Type NoteProperty -Name Status -Value $Incident.Status
$Event | Add-Member -Type NoteProperty -Name StartTime -Value (Get-Date($Incident.StartTime)).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss")
$Event | Add-Member -Type NoteProperty -Name LastUpdatedTime -Value (Get-Date($Incident.LastUpdatedTime)).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss")
$Event | Add-Member -Type NoteProperty -Name Details -Value $LatestMessage.MessageText
$Event | Add-Member -Type NoteProperty -Name NotificationRecipients $NotificationRecipients
$NewChangedEvents += @($Event)
}
}

ForEach ($Event in $NewChangedEvents)
{
#Build HTML for email
$MessageText = $Event.Details -replace("`n",'<br>') -replace([char]8217,"'") -replace([char]8220,'"') -replace([char]8221,'"') -replace('\[','<b><i>') -replace('\]','</i></b>')
$HTML = "<html>"
$HTML += "<style>"
$HTML += "BODY{font-family: Arial; font-size: 10pt;}"
$HTML += "H1{font-size: 22px;}"
$HTML += "H2{font-size: 18px; padding-top: 10px;}"
$HTML += "H3{font-size: 16px; padding-top: 8px;}"
$HTML += "H4{font-size: 12px; padding-top: 4px;}"
$HTML += "TABLE{border: 1px solid black; border-collapse: collapse; font-size: 8pt; table-layout: fixed; width: 800px;}"
$HTML += "TABLE.summary{text-align: center; width: auto;}"
$HTML += "TH{border: 1px solid black; background: #dddddd; padding: 5px; color: #000000;}"
$HTML += "TD{border: 1px solid black; padding: 5px; vertical-align: top; }"
$HTML += "td.pass{background: #7FFF00;}"
$HTML += "td.warn{background: #FFE600;}"
$HTML += "td.fail{background: #FF0000; color: #ffffff;}"
$HTML += "td.info{background: #85D4FF;}"
$HTML += "ul{list-style: inside; padding-left: 0px;}"
$HTML += ".firstrunnotice { font-size: 14px; color: #4286f4; }"
$HTML += "</style>"
$HTML += "<body>"
$HTML += "<table>"
$HTML += "<tr bgcolor=""#000099"">"
$HTML += " <td align=""center""><font color=""#ffffff"">Event ID</font></td>"
$HTML += " <td align=""center""><font color=""#ffffff"">Service</font></td>"
$HTML += " <td align=""center""><font color=""#ffffff"">Status</font></td>"
$HTML += " <td align=""center""><font color=""#ffffff"">Event Start Time</font></td>"
$HTML += " <td align=""center""><font color=""#ffffff"">Last Updated</font></td>"
$HTML += "</tr>"
$HTML += "<tr bgcolor=""#0000FF"">"
$HTML += " <td align=""center""><font color=""#ffffff"">$($Event.ID)</font></td>"
$HTML += " <td align=""center""><font color=""#ffffff"">$($Event.Service)</font></td>"
$HTML += " <td align=""center""><font color=""#ffffff"">$($Event.Status)</font></td>"
$HTML += " <td align=""center""><font color=""#ffffff"">$($Event.StartTime)</font></td>"
$HTML += " <td align=""center""><font color=""#ffffff"">$($Event.LastUpdatedTime)</font></td>"
$HTML += "<tr><td colspan=""5"" style=""border:none"">&nbsp;</td></tr>"
$HTML += "<tr>"
$HTML += " <td colspan=""5"">$MessageText<br/>&nbsp;<br/><a href=""http://o365health.ad.csbsju.edu/"">Office 365 Health Dashboard</a></td>"
$HTML += "</tr>"
$HTML += "<tr><td colspan=""5"" style=""border:none"">&nbsp;</td></tr>"
$HTML += "</table>"
$HTML += "</body>"
$HTML += "</html>"

#Send notification
Send-MailMessage -From $NotificationSender -To $NotificationRecipients -Subject "O365 Health Alert - $($Event.Service) [Event ID: $($Event.ID)]" -Body $HTML -BodyAsHtml -SmtpServer $SmtpServer -Port $SmtpPort -UseSsl
}

Highlighted

Hi All,

 

I'm sorry it took long for me to update this.

 

I have published a working, functional script that I am already using in production.

 

You can read through the post here:

https://www.lazyexchangeadmin.com/2018/10/shd365.html

 

I hope this helps.

 

 

 

Highlighted

@Shawn Beckers 

We are using almost same script which works just fine when run manually. However, when running as a scheduled job, it fails with below error. Initial auth token call is successful but fails on next call to retrieve messages. Any idea/suggestions? Appreciate it!

 

System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
--- End of inner exception stack trace ---
at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
--- End of inner exception stack trace ---
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()

Highlighted

@Rahul Babar 

I believe I've run into that error, or a similar one, when connections are being blocked by firewall or some other locally running security app.  Do you have anything like that running on this machine?  If so, I'd suggest temporarily disabling to see if that allows you to run the scheduled script.