Reputation: 51
I'm trying to pull data for a getOneDriveUsageAccountDetail REST GET from PowerShell. The trouble is that by default it will only return 200 items, I've managed to get it to return 10000 items, I think this is a hard limit. But I need to get all the items, or be able to query the report for one user, or a batch of users. This doesn't appear to be possible.
I've found I can add &%24top=10000
to my URI to return 10000 results.
The only parameters are period and date.
I have an Initialize-Authorization function to create an $script:APIHeader to store an access token. This works fine.
This is the function I'm using to generate the report.
Function Get-GraphOneDriveUsageAccountDetail {
$result = (Invoke-RestMethod `
-Method get `
-Uri "https://graph.microsoft.com/beta/reports/getOneDriveUsageAccountDetail(period='D180')?%24format=application%2Fjson&%24top=10000" `
-ContentType 'application/json' `
-Headers $script:APIHeader `
-ErrorAction Stop).value
return $result
}
Upvotes: 1
Views: 421
Reputation: 51
This was my final code:
Function Get-GraphOneDriveUsageAccountDetail {
$AccountDetail = Invoke-RestMethod `
-Method get `
-Uri "https://graph.microsoft.com/beta/reports/getOneDriveUsageAccountDetail(period='D180')?%24format=application%2Fjson&%24top=10000" `
-ContentType 'application/json' `
-Headers $script:APIHeader `
-ErrorAction Stop
$result = $AccountDetail.value
While($AccountDetail.'@odata.nextLink')
{
Write-Verbose "Next Link $($AccountDetail.'@odata.nextLink')" -Verbose
$AccountDetail = Invoke-RestMethod `
-Method get `
-Uri $AccountDetail.'@odata.nextLink' `
-ContentType 'application/json' `
-Headers $script:APIHeader `
-ErrorAction Stop
$result += $AccountDetail.value
}
return $result
}
Upvotes: 0
Reputation: 33114
Most Graph endpoints return paged data:
Some queries against Microsoft Graph return multiple pages of data either due to server-side paging or due to the use of the
$top
query parameter to specifically limit the page size in a request. When a result set spans multiple pages, Microsoft Graph returns an@odata.nextLink
property in the response that contains a URL to the next page of results.
You need to follow the nextLink
in the result to retrieve the next page (the last page is the first result without a nextLink
).
Upvotes: 1