Need to get Intune device's primary UPN using microsoft graph, rather then enrolled upn

Leon Prentice 11 Reputation points
2022-06-20T11:25:51.977+00:00

Hello,

I'm setting up a report using microsoft graph via powershell to return device data where we can compare primary user and last logged on user. At the minute, using "https://graph.microsoft.com/beta/deviceManagement/managedDevices?&$select=deviceName,usersLoggedOn,userDisplayName,userPrincipalName,userId" is returning the enrolled user Id, principal name, and display name instead of the assigned primary user.

How are we able to find out the primary user using microsoft graph?

Thanks

Microsoft Security Intune Other
Microsoft Security Microsoft Graph
{count} votes

4 answers

Sort by: Most helpful
  1. Srinivasa Rao Darna 6,761 Reputation points Microsoft External Staff
    2022-06-20T15:31:06.47+00:00

    Hi @Leon Prentice ,

    Currently with Intune Graph API's we can only get Enrolled user with list-manageddevice GET /beta/deviceManagement/managedDevices.

    We can get the primary users associated with the managed device for a specified managedDeviceId and this API/endpoint is only available in /beta now get-manageddevice.

    GET /beta/deviceManagement/managedDevices/{managedDeviceId}/users  
    

    APIs under the /beta version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported.

    Reference docs: intune-devices-manageddevice

    Additionally refer to this Intune Graph API with PowerShell that can help you get all devices and primary users PrimaryUser_Get.

    Hope this helps.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have further questions about this answer, please click "Comment".

    1 person found this answer helpful.

  2. Sulli, Russell (HQP) 5 Reputation points
    2023-02-15T22:50:41.6+00:00

    Hello, is there any timeframe on when we will be able to query for the primary user?

    1 person found this answer helpful.
    0 comments No comments

  3. Konstantinos Passadis 19,586 Reputation points MVP
    2023-05-24T21:38:10.16+00:00

    Hello @Leon Prentice !

    Regarding permissions i believe these are required

    • DeviceManagementManagedDevices.PrivilegedOperations.All
    • DeviceManagementManagedDevices.ReadWrite.All
    • Group.Read.All
    • GroupMember.Read.All
    • Organization.Read.All
    • User.Read.All

    I hope this helps!

    Kindly mark the answer as Accepted and Upvote in case it helped!

    Regards

    1 person found this answer helpful.

  4. Souders, Justin 25 Reputation points
    2023-02-16T16:27:29.1333333+00:00

    I am also trying to get the primary user assigned to a device, but I am getting a 403 returned when using the following endpoint.

    https://graph.microsoft.com/beta/deviceManagement/managedDevices/{managedDeviceId}/users
    
    

    I can successfully call the same endpoint without the users.

    https://graph.microsoft.com/beta/deviceManagement/managedDevices/{managedDeviceId}
    

    Are there additional permissions needed to get the users of a managed device?

    I currently have the app role of DeviceManagementManagedDevices.Read.All assigned to this system managed identity and utilizing it from an Azure automation account runbook.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.