microsoftgraph / msgraph-sdk-powershell

Powershell SDK for Microsoft Graph
https://www.powershellgallery.com/packages/Microsoft.Graph
Other
715 stars 172 forks source link

Update-MgDeviceManagementManagedDevice not working #2551

Open compluct opened 10 months ago

compluct commented 10 months ago

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

BenjaminNiemann commented 8 months ago

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.

3DBarron commented 7 months ago

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.

talkingoldfish commented 5 months ago

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
        }
    }
}
xenoguy commented 1 month ago

This is still a problem in october.

I tried using the beta cmdlets (get-mgbetauser, update-mgbetadevicemanagementmanageddevice) and it complains about a different property, "onPremisesObjectIdentifier"