lwhitelock / HuduM365Automation

Hudu Microsoft 365 Syncronisation Tool
GNU Affero General Public License v3.0
29 stars 72 forks source link

EPM Device is matching users on Enrollment User instead of Primary User #12

Open mpowelltech opened 1 year ago

mpowelltech commented 1 year ago

I have noticed that the script is matching devices to users based on the user who enrolled the device, instead of who is the Primary User.

Given that the Primary user is what is usually used to track the device owner, I would suggest using this instead if possible.

My research tells me that https://graph.microsoft.com/v1.0/deviceManagement/managedDevices annoyingly returns only the enrollment user, which I assume is why this is used instead of Primary user. I believe you should be able to use https://graph.microsoft.com/v1.0/deviceManagement/managedDevices/{managedDevice-id}/users (then get the .value.userPrincipalName field from this result instead to get the Primary User, though I don't have the exact know-how of how to do this to create a pull request.

Thanks!