We have recently faced issues with few of our automations that were fetching all the managed devices using below command:
Get-IntuneManagedDevice | Get-MSGraphAllPages
Our automations were working since last 2 years and suddenly in September 2021, these started giving issues, on troubleshooting more we have found that above command was only returning 950 devices whereas we have around 30000 devices in our tenant.
We have also tried using paging but issue we have found .”@odata.nextLink” is coming as empty.
———————————————————————————————————————————
$url = https://graph.microsoft.com/v1.0/deviceManagement/managedDevices
$Response = Invoke-MSGraphRequest -HttpMethod GET -Url $url -Verbose
$getalldevices = $Response.value
$NextLink = $Response.”@odata.nextLink”
$count = 0
while ($NextLink -ne $null)
{
$count = $count + 1
$Response = (Invoke-MSGraphRequest -HttpMethod GET -Url $NextLink -Verbose)
Write-Log -Message “Processing Page …..$count” -path $log
$NextLink = $Response.”@odata.nextLink”
$getalldevices += $Response.value
}
———————————————————————————————————————————
On working with Microsoft, it has been discovered that a design has been changed (below is response from PG).
Soon public documentation will be updated.
I have now the confirmation from our product group that the issue your are experiencing is by-design if data is unfiltered and the data set is large
which I believe it’s your case. One possible workaround for this is to e.g. query all Android devices first then all iOS and later all Windows devices.
Therefore, to resolve this issue we must update the code and add some filter as shown in example.
Get-IntuneManagedDevice -Filter “managementagent eq ‘mdm'” | Get-MSGraphAllPages
After filtering the query first and adding Get-MSGraphAllPages afterwards, all pages/devices will be shown.
I am sure there are others admins that might be in the same boat and now you have find the solution 🙂
Thanks for reading …
Tech Wizard
https://techwizard.cloud
https://syscloudpro.com/