how to get list of all devices from intune via Graph.Intune namespace in .Net?

na 121 Reputation points
2022-07-06T14:55:09.66+00:00

I am trying to get a list of all devices in InTune, using c# /.Net.
All examples show how to do this on a per user basis only, but this seems inefficient, to have to iterate through all users.

There appears to be a Powershell command that can do this. is this functionality available in the Microsoft.Graph .net namespace?
I have been unable to find it.

Microsoft Intune
Microsoft Intune
A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.
4,449 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Crystal-MSFT 43,996 Reputation points Microsoft Vendor
    2022-07-07T02:04:31.543+00:00

    @na , Based on my test in my lab, I find we can using the following method to get all the managed devices in graph.

    1. Open Intune portal, press F12 to open Devtools. Add Network console to capture the network record.
    2. Click Devices->All devices in Intune portal.
    3. Then stop record and go to check the request information. I find the request is as below:
      Request method: Get
      Request URl: https://graph.microsoft.com/beta/deviceManagement/managedDevices?$filter=(Notes%20eq%20%27bc3e5c73-e224-4e63-9b2b-0c36784b7e80%27)&$top=25&$skipToken=Skip=%270%27&$select=deviceName,managementAgent,ownerType,complianceState,deviceType,userId,userPrincipalName,osVersion,lastSyncDateTime,userPrincipalName,id,deviceRegistrationState,managementState,exchangeAccessState,exchangeAccessStateReason,deviceActionResults,deviceEnrollmentType

    218359-image.png
    4. You can find the one in your environment and try to request in graph explorer to get the managed device information:
    218318-image.png

    Hope it can help.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. na 121 Reputation points
    2022-07-07T08:59:25.08+00:00

    Thanks @Crystal-MSFT

    How do i execute that ODATA url in .net core though?
    Ive used the graph api in .net to query users, but it does not seem to have the flexibility thats available via odata calls in Graph Explorer.


  3. na 121 Reputation points
    2022-07-08T11:16:52.427+00:00

    Thanks @Crystal-MSFT

    There is a graph API which is very useful, but limited and does not appear to provide access to devices, only to query devices on a per person/UPN basis.
    I have managed to access this using a more generic http request, obtain a token from azure identity and create the URL within the .NET app.

    Requires more coding but it works.

    Thank you for your help and direction on this.