MS Graph API - 如何查询其他页面

问题描述 投票:0回答:1

我不确定如何查询其他页面。通过一些指南,我看到我已经拼凑了以下内容,但只获得了前 1000 个结果(预计数字接近 15000)。我似乎无法捕获 @odata.nextLink 值以添加到循环中。

$DeviceList = @()    
$URI = "https://graph.microsoft.com/v1.0/deviceManagement/managedDevices?`$filter=contains(OperatingSystem,'iOS')&?`$select=serialNumber,Id"

if ($Null -ne $URI) 
    {
    $GetDevices = Invoke-RestMethod -Headers $Headers -Uri $URI
    $DeviceList += $GetDevices.value
    $URI = $GetDevices.'@Odata.nextLink'
    }

$DeviceList | Export-Csv C:\Users\######\Downloads\Test.csv -Force -Append
azure powershell pagination microsoft-graph-api microsoft-graph-intune
1个回答
1
投票

要处理分页,您可以使用

do
循环
$uri.'@odata.nextLink'
的值重新分配给变量,循环中断条件可以是,同时存在
nextLink

$uri = 'htts://graph.microsoft.com/.....'

& {
    do {
        $uri = Invoke-RestMethod -Headers $Headers -Uri $uri
        $uri.Value
        $uri = $uri.'@Odata.nextLink'
    } while($uri)
} | Export-Csv path\to\export.csv -NoTypeInformation
© www.soinside.com 2019 - 2024. All rights reserved.