Skip to content

Instantly share code, notes, and snippets.

@poiriersimon
Last active September 21, 2018 17:40
Show Gist options
  • Save poiriersimon/28e5185bf2836677e27a497d7d1c1e99 to your computer and use it in GitHub Desktop.
Save poiriersimon/28e5185bf2836677e27a497d7d1c1e99 to your computer and use it in GitHub Desktop.
Sample Powershell Script to check the Health of Office 365 Environment with Office 365 Management API
#Create an Web Azure AD Application + Key
#Permission - Office 365 Management APIs (both App and Impersonation)
# - Read service health information for your organization
# - Read activity data for your organization
# Don't forget to click on Grant Permission
# Based on https://github.com/OfficeDev/O365-InvestigationTooling/blob/master/O365InvestigationDataAcquisition.ps1
#Pre-reqs for REST API calls
$ClientID = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
$ClientSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
$tenantdomain = "TENANTNAME.onmicrosoft.com"
#https://login.windows.net/multihybrid.onmicrosoft.com/.well-known/openid-configuration
$TenantGUID = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
#Service to report on
[array]$O365Service = "Exchange Online","Microsoft Intune","Microsoft Teams","Mobile Device Management for Office 365","OneDrive for Business","Identity Service","Office 365 Portal","Office Subscription","SharePoint Online","Sway","Planner","Yammer Enterprise"
#API Info
$loginURL = "https://login.windows.net/"
$resource = "https://manage.office.com"
# Get an Oauth 2 access token based on client id, secret and tenant domain
$body = @{grant_type="client_credentials";resource=$resource;client_id=$ClientID;client_secret=$ClientSecret}
$oauth = Invoke-RestMethod -Method Post -Uri $loginURL/$tenantdomain/oauth2/token?api-version=1.0 -Body $body
#Let's put the oauth token in the header, where it belongs
$headerParams = @{'Authorization'="$($oauth.token_type) $($oauth.access_token)"}
#GET
$operation = "CurrentStatus"
$uri = "https://manage.office.com/api/v1.0/$TenantGUID/ServiceComms/$($operation)"
$tenantInfo = (Invoke-RestMethod -Uri $uri –Headers $headerParams –Method Get –Verbose).value
$ServiceInfo = $tenantInfo| Select-Object WorkloadDisplayName,Status,ID,StatusDisplayName
$TableauEXOTable = @()
foreach($Service in $ServiceInfo){
if($O365Service -contains $Service.WorkloadDisplayName){
$TableauEXOObj = New-Object PSObject
$TableauEXOObj | Add-Member NoteProperty -Name "Service" -Value $Service.WorkloadDisplayName
$TableauEXOObj | Add-Member NoteProperty -Name "Service Status" -Value $Service.StatusDisplayName
[array]$TableauEXOTable += $TableauEXOObj
}
}
return $TableauEXOTable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment