Last active
February 19, 2016 08:47
-
-
Save alexinnes/0b6983c75e30ea7f5e99 to your computer and use it in GitHub Desktop.
Gets the health events from O365 via API call.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.Synopsis | |
Gets office 365 events | |
.DESCRIPTION | |
Users the Office 365 API to get all events. | |
.EXAMPLE | |
get-O365Events | |
.EXAMPLE | |
get-O365Events -last 5 | |
[Can add username in now] | |
get-O365Events -username email@address.com | |
#> | |
function Get-O365Events | |
{ | |
[CmdletBinding()] | |
[Alias()] | |
[OutputType([int])] | |
Param | |
( | |
# Param1 help description | |
[Parameter(Mandatory=$false, | |
ValueFromPipelineByPropertyName=$false, | |
Position=0)] | |
[int]$last = 0, | |
[string]$username | |
) | |
Begin | |
{ | |
Try{ | |
$cred = Get-Credential -Message "Office 365 Credentials" -UserName $username | |
$Json = (@{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 $json).RegistrationCookie | |
#preferredEventType -- "0" to represents a Service Incident, "1" to represent a Maintenance Event, and "2" to represent a Message Center communication | |
$load = (@{lastCookie=$cookie;locale="en-US";preferredEventTypes=@(0,1,2);} | convertto-json).tostring() | |
$events = (invoke-restmethod -contenttype "application/json" -method Post -uri "https://api.admin.microsoftonline.com/shdtenantcommunications.svc/GetEvents" -body $load) | |
} | |
Catch{ | |
Write-Warning -Message "Please Check your credentials"; break | |
} | |
Finally{} | |
} | |
Process | |
{ | |
$newEvent = foreach($evnt in $events.events){ | |
New-Object psobject -Property @{ | |
ID = $evnt.ID | |
Title = $evnt.Title | |
ServiceAftected = $evnt.AffectedServiceHealthStatus.servicename | |
Status = $evnt.Status | |
Time = $evnt.starttime | |
LastUpdated = $evnt.LastUpdatedTime | |
Message = $evnt.messages.messagetext | |
} | |
} | |
} | |
End | |
{ | |
if($last -eq 0){$last = 10} | |
$newEvent| sort -property Time | select -Property Title,ServiceAftected,Status, Time,LastUpdated, message -Last $last | fl | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
API has stopped working - I will need to update this.