msgraph-sdk-powershell icon indicating copy to clipboard operation
msgraph-sdk-powershell copied to clipboard

Update-MgDeviceManagementManagedDevice not working

Open ghost opened this issue 2 years ago • 5 comments

Describe the bug If I want to update a primary user of a device using the Update-MgDeviceManagementManagedDevice command, I get an error message stating the property 'businessPhones' does not exist on type 'microsoft.management.services.api.user'.

To Reproduce Input: $user = Get-MgUser -UserId "00000" Update-MgDeviceManagementManagedDevice -ManagedDeviceId "00000" -Users $user

Output: The property 'businessPhones' does not exist on type 'microsoft.management.services.api.user'. Make sure to only use property names that are defined by the type. Status: 400 (BadRequest)

Expected behaviour The primary user should be successfully changed.

Module Version Newest, currently aviable version.

Additional context I already created a Service request with the API owner as required in Issue 1675, and they told me that it is on your side to fix the PowerShell SDK. On the API side everything is working fine. Please don't close the issue again! There is also an answer by another Microsoft employee related to this issue: https://learn.microsoft.com/en-us/answers/questions/1506439/changing-primary-user-of-a-device-in-intune

ghost avatar Jan 31 '24 13:01 ghost

The same problem exists here unfortunately! You cannot specify the user by any other string (ID or UPN). Therefore, you need to specify a compatible data type with the correct Businessphone parameter.

BenjaminNiemann avatar Mar 19 '24 09:03 BenjaminNiemann

Having this issue as well- it seems it's literally impossible to update the primary user of a device with mg-graph currently, which is a huge problem for administrators who might need to do bulk changes. I guess I'm now doing several hundred by hand- and it seems this was reported as far back as at least 2 years ago with no fix... very frustrating that the old modules are deprecated but the new modules are missing baseline functionality.

3DBarron avatar Apr 09 '24 16:04 3DBarron

I know this is an old thread, but I have just had the same issue and there is still a way to do this in MS Graph, using Invoke-MgGraphRequest

It requires the Intune Device ID and the User ID to update the user, part of my script is as below to update all of our Primary Users to the last logged on user for the device (this uses the Get-MgBetaDeviceManagementManagedDevice command so we can grab all device users):

Get-MgBetaDeviceManagementManagedDevice -Filter "managedDeviceOwnerType eq 'company' and OperatingSystem eq 'Windows'" -All |
    Sort-Object DeviceName | ForEach-Object {
    $intuneDeviceID = $_.Id

    $user = @($_.UsersLoggedOn | Sort-Object LastLogOnDateTime -Descending)[0]
    $userId = $user.UserId
    
    if ($userId) {
        $mgUser = Get-MgUser -UserId $userId -ErrorAction SilentlyContinue
    
        if ($mgUser -and $_.UserPrincipalName -ne $mgUser.UserPrincipalName) {
            $uri = "https://graph.microsoft.com/beta/deviceManagement/managedDevices('$intuneDeviceID')/users/`$ref"
            $body = @{ "@odata.id" = "https://graph.microsoft.com/beta/users/$userId" } | ConvertTo-Json
    
            Invoke-MgGraphRequest -Method POST -uri $uri -body $body
        }
    }
}

talkingoldfish avatar Jun 26 '24 09:06 talkingoldfish