-
Notifications
You must be signed in to change notification settings - Fork 214
/
SARA_utils.ps1
66 lines (54 loc) · 1.74 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
64
65
66
# 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-Verbose "Retrieving information.."
if($response.ProcessingStatus -eq "Queued")
{
Start-Sleep -Seconds "2"
}
$response = Invoke-RestMethod -UseBasicParsing -Uri "$url/?id=$sessionId" -Method Get -Headers $headers
}
# Return
$response
}
}