-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFind-Groups.ps1
90 lines (69 loc) · 2.85 KB
/
Find-Groups.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
#Setup required variables
$uri = "/api/directory/find-groups"
$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"": [
{
""query"": ""Permitted""
}
]
}"
#Send Request
$response = Invoke-RestMethod -Method Post -Headers $headers -Body $postBody -Uri $url
#Print the response
$response.data.folders.id | ConvertTo-Json
$membersId = $response.data.folders.id
#find members of that group
$uri = "/api/directory/get-group-members"
$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"": [
{
""id"": $membersId
}
]
}"
#Send Request
$response = Invoke-RestMethod -Method Post -Headers $headers -Body $postBody -Uri $url
#Print the response
$response.data | ConvertTo-Json