With Graph API we are only getting 1000 devices

Brass Contributor

HI Team,


We are using the below PowerShell script to change the Primary user of a device by checking the last logged in userid.


Below is the github repo link which holds this PowerShell script and also the link of an article about the explanation of this script -


The problem now is that we are only able to get 1000 devices in the $Devices variable in the above mentioned script and we have around 2000 devices so 1000 more devices are not getting fetched by this script.


Also this script always get the device in the same pattern i.e.. if I run the script today and tomorrow then the devices will show the same pattern that is also the reason the rest 1000 devices are not getting fetched.


Any solution to this issue will be a great help for me. 



Ashish Arya



2 Replies
best response confirmed by Ashish_Arya (Brass Contributor)
HI maybe this could help you solve it?

"@odata.count": 1000,

Thanks a lot @Rudy_Ooms_MVP for your reply.
This has fixed my issue. Now I am able to get the other devices as well.


Below if the code which I added to script - 


$DevicesResponse = (Invoke-RestMethod -Uri $uri -Headers $authToken -Method Get)

$Devices = $DevicesResponse.value

$DevicesNextLink = $DevicesResponse."@odata.nextLink"

while ($DevicesNextLink -ne $null){

$DevicesResponse = (Invoke-RestMethod -Uri $DevicesNextLink -Headers $authToken -Method Get)
$DevicesNextLink = $DevicesResponse."@odata.nextLink"
$Devices += $DevicesResponse.value


return $Devices


Below is the script for reference: