SOLVED

With Graph API we are only getting 1000 devices

%3CLINGO-SUB%20id%3D%22lingo-sub-2682870%22%20slang%3D%22en-US%22%3EWith%20Graph%20API%20we%20are%20only%20getting%201000%20devices%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2682870%22%20slang%3D%22en-US%22%3E%3CP%3EHI%20Team%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWe%20are%20using%20the%20below%20PowerShell%20script%20to%20change%20the%20Primary%20user%20of%20a%20device%20by%20checking%20the%20last%20logged%20in%20userid.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBelow%20is%20the%20github%20repo%20link%20which%20holds%20this%20PowerShell%20script%20and%20also%20the%20link%20of%20an%20article%20about%20the%20explanation%20of%20this%20script%20-%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fraw.githubusercontent.com%2Fsvdbusse%2FIntuneScripts%2Fmaster%2FPrimaryUser%2FSet-PrimaryUserfromLastLogIn.ps1%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fraw.githubusercontent.com%2Fsvdbusse%2FIntuneScripts%2Fmaster%2FPrimaryUser%2FSet-PrimaryUserfromLastLogIn.ps1%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fsvdbusse.github.io%2FSemiAnnualChat%2F2020%2F03%2F21%2FChanging-Intune-Primary-User-To-Last-Logged-On-User.html%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fsvdbusse.github.io%2FSemiAnnualChat%2F2020%2F03%2F21%2FChanging-Intune-Primary-User-To-Last-Logged-On-User.html%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20problem%20now%20is%20that%20we%20are%20only%20able%20to%20get%201000%20devices%20in%20the%20%24Devices%20variable%20in%20the%20above%20mentioned%20script%20and%20we%20have%20around%202000%20devices%20so%201000%20more%20devices%20are%20not%20getting%20fetched%20by%20this%20script.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%20this%20script%20always%20get%20the%20device%20in%20the%20same%20pattern%20i.e..%20if%20I%20run%20the%20script%20today%20and%20tomorrow%20then%20the%20devices%20will%20show%20the%20same%20pattern%20that%20is%20also%20the%20reason%20the%20rest%201000%20devices%20are%20not%20getting%20fetched.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20solution%20to%20this%20issue%20will%20be%20a%20great%20help%20for%20me.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%2C%3C%2FP%3E%3CP%3EAshish%20Arya%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2682870%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EGraph%20API%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMobile%20Device%20Management%20(MDM)%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2683487%22%20slang%3D%22en-US%22%3ERe%3A%20With%20Graph%20API%20we%20are%20only%20getting%201000%20devices%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2683487%22%20slang%3D%22en-US%22%3EHI%20maybe%20this%20could%20help%20you%20solve%20it%3F%3CBR%20%2F%3E%3CBR%20%2F%3E%22%40odata.count%22%3A%201000%2C%3CBR%20%2F%3E%22%40odata.nextLink%22%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fgraph%2Fpaging%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fgraph%2Fpaging%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2699504%22%20slang%3D%22en-US%22%3ERe%3A%20With%20Graph%20API%20we%20are%20only%20getting%201000%20devices%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2699504%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20a%20lot%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F620702%22%20target%3D%22_blank%22%3E%40Rudy_Ooms%3C%2FA%3E%20for%20your%20reply.%3CBR%20%2F%3EThis%20has%20fixed%20my%20issue.%20Now%20I%20am%20able%20to%20get%20the%20other%20devices%20as%20well.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBelow%20if%20the%20code%20which%20I%20added%20to%20script%20-%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24DevicesResponse%20%3D%20(Invoke-RestMethod%20-Uri%20%24uri%20-Headers%20%24authToken%20-Method%20Get)%3C%2FP%3E%3CP%3E%24Devices%20%3D%20%24DevicesResponse.value%3C%2FP%3E%3CP%3E%24DevicesNextLink%20%3D%20%24DevicesResponse.%22%40odata.nextLink%22%3C%2FP%3E%3CP%3Ewhile%20(%24DevicesNextLink%20-ne%20%24null)%7B%3C%2FP%3E%3CP%3E%24DevicesResponse%20%3D%20(Invoke-RestMethod%20-Uri%20%24DevicesNextLink%20-Headers%20%24authToken%20-Method%20Get)%3CBR%20%2F%3E%24DevicesNextLink%20%3D%20%24DevicesResponse.%22%40odata.nextLink%22%3CBR%20%2F%3E%24Devices%20%2B%3D%20%24DevicesResponse.value%3C%2FP%3E%3CP%3E%7D%3C%2FP%3E%3CP%3Ereturn%20%24Devices%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBelow%20is%20the%20script%20for%20reference%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoftgraph%2Fpowershell-intune-samples%2Fblob%2Fmaster%2FPaging%2FManagedDevices_Get_Paging.ps1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fmicrosoftgraph%2Fpowershell-intune-samples%2Fblob%2Fmaster%2FPaging%2FManagedDevices_Get_Paging.ps1%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional 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 (Occasional 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 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...