forked from Gerenios/AADInternals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SARA_utils.ps1
63 lines (51 loc) · 1.65 KB
/
SARA_utils.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
# Jul 8th 2019
function Call-AnalysisAPI
{
[cmdletbinding()]
Param(
[ValidateSet('userInfo','tenantInfo','cloudCheck')]
[String]$Command,
[Parameter(Mandatory=$True)]
[String]$AccessToken,
[Parameter(Mandatory=$True)]
[String]$Body,
[Parameter(Mandatory=$False)]
[String]$Url="https://api.diagnostics.office.com/v1/analysis"
)
Process
{
$headers =@{
"Content-Type" = "application/json;odata=verbose"
"Accept" = "application/json; charset=utf-8"
"Authorization" = $(Create-AuthorizationHeader -AccessToken $AccessToken -ClientId "d3590ed6-52b3-4102-aeff-aad2292ab01c" -Resource "https://api.diagnostics.office.com")
"x-ms-sara-api-version" = "schema-v1"
"User-Agent" = "saraclient"
}
try
{
$response = Invoke-RestMethod -UseBasicParsing -Uri $url -Method Post -Body $body -Headers $headers
}
catch
{
# Okay, something went wrong
return $null
}
if($url.EndsWith("/analysis"))
{
$sessionId = $response.SessionId
}
else
{
$sessionId = $response.RequestId
}
while($response.RequestStatus -ne "Completed" -and $response.RequestStatus -ne "Failed")
{
Write-Host "Retrieving information.."
sleep -Seconds "2"
$response = Invoke-RestMethod -UseBasicParsing -Uri "$url/?id=$sessionId" -Method Get -Headers $headers
}
# Return
$response
}
}