-
Notifications
You must be signed in to change notification settings - Fork 4
/
BlockedSenders-GetPolicy.ps1
39 lines (31 loc) · 1.3 KB
/
BlockedSenders-GetPolicy.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
#Setup required variables
$uri = "/api/policy/blockedsenders/get-policy"
$parameters = Get-Content -Raw -Path configuration.json | ConvertFrom-Json
$url = $parameters.baseUrl + $uri
$accessKey = $parameters.accessKey
$secretKey = $parameters.secreyKey
$appId = $parameters.appID
$appKey = $parameters.appKey
#Generate request header values
$hdrDate = (Get-Date).ToUniversalTime().ToString("ddd, dd MMM yyyy HH:mm:ss UTC")
$requestId = [guid]::NewGuid().guid
#Create the HMAC SHA1 of the Base64 decoded secret key for the Authorization header
$sha = New-Object System.Security.Cryptography.HMACSHA1
$sha.key = [Convert]::FromBase64String($secretKey)
$sig = $sha.ComputeHash([Text.Encoding]::UTF8.GetBytes($hdrDate + ":" + $requestId + ":" + $uri + ":" + $appKey))
$sig = [Convert]::ToBase64String($sig)
#Create Headers
$headers = @{"Authorization" = "MC " + $accessKey + ":" + $sig;
"x-mc-date" = $hdrDate;
"x-mc-app-id" = $appId;
"x-mc-req-id" = $requestId;
"Content-Type" = "application/json"}
#Create post body
$postBody = "{
""data"": [
]
}"
#Send Request
$response = Invoke-RestMethod -Method Post -Headers $headers -Body $postBody -Uri $url
#Print the response
$response.data | ConvertTo-Json