-
Notifications
You must be signed in to change notification settings - Fork 1
/
Get-Microsoft365Status.ps1
105 lines (74 loc) · 2.77 KB
/
Get-Microsoft365Status.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
Clear-Host
<#Information
Author: thewatchernode
Contact: author@blogabout.cloud
Published: 30th Ocotber 2020
.DESCRIPTION
Tool to gather Microsoft 365 Health Status.
# IMPORTANT
Office 365 Service Communications API needs to be configured with your Tenant. http://www.blogabout.cloud/2020/10/1884/
Version Changes
: 0.1 Initial Script Build
: 1.0 Initial Build Release
Credit:
.EXAMPLE
.\Get-Microsoft365Status.ps1
Description
-----------
Runs script with default values.
.INPUTS
None. You cannot pipe objects to this script.
#>
#region To be configured by the script runner
# Objects
$tenantId = ''
$client_id = ''
$client_secret = ''
$path = "$env:USERPROFILE\desktop\M365Status_Log.txt"
#endregion
#region Shortnames
$Red = 'Red'
$Green = 'Green'
$DarkRed = 'DarkRed'
$White = 'White'
$DarkCyan = 'DarkCyan'
$DarkGray = 'DarkGray'
#endregion
Function Get-M365Status {
# Construct URI for OAuth Token
$uri = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token"
# Construct Body for OAuth Token
$body = @{
client_id = $client_id
scope = "https://manage.office.com/.default"
client_secret = $client_secret
grant_type = "client_credentials"
}
# Get OAuth 2.0 Token
$tokenRequest = try {
Invoke-RestMethod -Method Post -Uri $uri -ContentType "application/x-www-form-urlencoded" -Body $body -ErrorAction Stop
}
catch [System.Net.WebException] {
Write-Warning "Exception was caught: $($_.Exception.Message)"
}
$token = $tokenRequest.access_token
# Get Office 365 Status
$m365status = try {
Invoke-RestMethod -Method Get -Uri "https://manage.office.com/api/v1.0/$tenantid/ServiceComms/CurrentStatus" -ContentType "application/json" -Headers @{Authorization = "Bearer $token"} -ErrorAction Stop
}
catch [System.Net.WebException] {
Write-Warning "Exception was caught: $($_.Exception.Message)"
}
# List service overview status
$m365status.Value | Format-Table WorkloadDisplayName, StatusDisplayName, Status, IncidentIds
}
Write-host 'Version information - You are running script version 1.0' -ForegroundColor $White -BackgroundColor $DarkGray
@'
┌─────────────────────────────────────────────────────────────┐
Gather the status of Microsoft 365 Service Health
Follow @thewatchernode on Twitter
└─────────────────────────────────────────────────────────────┘
'@
Start-Transcript -Path $path
Get-M365Status
Stop-Transcript