forked from anwather/My-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExport-MessageCenter.ps1
More file actions
55 lines (42 loc) · 1.48 KB
/
Copy pathExport-MessageCenter.ps1
File metadata and controls
55 lines (42 loc) · 1.48 KB
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
Param([string]$ClientKey, [string]$ClientAppId, [string]$TenantId)
function GetAuthToken {
[CmdletBinding()]
Param (
$ClientID, $ClientSecret, $TenantID
)
$TokenEndpoint = "https://login.windows.net/{0}/oauth2/token" -f $TenantID
$ARMResource = "https://manage.office.com";
$Body = @{
'resource' = $ARMResource
'client_id' = $ClientID
'grant_type' = 'client_credentials'
'client_secret' = $ClientSecret
}
$params = @{
ContentType = 'application/x-www-form-urlencoded'
Headers = @{'accept' = 'application/json' }
Body = $Body
Method = 'Post'
URI = $TokenEndpoint
}
$token = Invoke-RestMethod @params
return $token
}
$token = (GetAuthToken -ClientID $ClientAppId -ClientSecret $ClientKey -TenantID $TenantId).access_token
$headers = @{
Authorization = "Bearer $token"
PublisherIdentifier = $tenantId
ContentType = 'application/json'
}
$testCall = "https://manage.office.com/api/v1.0/$tenantId/ServiceComms/Messages"
$result = Invoke-RestMethod -Uri $testCall -Headers $headers -Verbose
$output = @()
foreach ($message in $result.value) {
$obj = [PSCustomObject]@{
Id = $message.Id
Title = $message.Title
Message = $message.Messages.MessageText -join "`n"
}
$output += $obj
}
$output | Export-CSV -Path message.csv -NoTypeInformation