-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMS Graph Paging Function.ps1
More file actions
49 lines (36 loc) · 1.43 KB
/
MS Graph Paging Function.ps1
File metadata and controls
49 lines (36 loc) · 1.43 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
$clientID = 'yourClientID'
$tenantId = 'yourTenantID'
$Clientsecret = 'yourSecret'
#Auth MS Graph API and Get Header
$tokenBody = @{
Grant_Type = "client_credentials"
Scope = "https://graph.microsoft.com/.default"
Client_Id = $clientID
Client_Secret = $Clientsecret
}
$tokenResponse = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$tenantID/oauth2/v2.0/token" -Method POST -Body $tokenBody
$headers = @{
"Authorization" = "Bearer $($tokenResponse.access_token)"
"Content-type" = "application/json"
}
function Get-AzureResourcePaging {
param (
$URL,
$AuthHeader
)
# List Get all Apps from Azure
$Response = Invoke-RestMethod -Method GET -Uri $URL -Headers $AuthHeader
$Resources = $Response.value
while ($null -ne $($Response."@odata.nextLink")) {
$Response = (Invoke-RestMethod -Uri $($Response."@odata.nextLink") -Headers $AuthHeader -Method Get)
$Resources += $Response.value
}
if ($null -eq $Resources) {
$Resources = $Response
}
return $Resources
}
#Examples
$AllDevices = Get-AzureResourcePaging -URL "https://graph.microsoft.com/v1.0/devices" -AuthHeader $headers
$AllUsers = Get-AzureResourcePaging -URL "https://graph.microsoft.com/v1.0/users" -AuthHeader $headers
$AllApplications = Get-AzureResourcePaging -URL "https://graph.microsoft.com/v1.0/applications" -AuthHeader $headers