SOLVED

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 - 

 

https://raw.githubusercontent.com/svdbusse/IntuneScripts/master/PrimaryUser/Set-PrimaryUserfromLastL...

 

https://svdbusse.github.io/SemiAnnualChat/2020/03/21/Changing-Intune-Primary-User-To-Last-Logged-On-...

 

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. 

 

Regards,

Ashish Arya

 

 

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

"@odata.count": 1000,
"@odata.nextLink":

https://docs.microsoft.com/en-us/graph/paging

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:

 

https://github.com/microsoftgraph/powershell-intune-samples/blob/master/Paging/ManagedDevices_Get_Pa...

 

 

1 best response

Accepted Solutions
best response confirmed by Ashish_Arya (Brass Contributor)
Solution
HI maybe this could help you solve it?

"@odata.count": 1000,
"@odata.nextLink":

https://docs.microsoft.com/en-us/graph/paging

View solution in original post