microsoft / Intune-PowerShell-SDK

Native PowerShell support for invoking Microsoft Intune Graph API to enable IT Pro scenario automation.
MIT License
314 stars 77 forks source link

Update-mgdevicemanagementmanageddevice -devicecategory #145

Open SamSepiolWarden opened 1 year ago

SamSepiolWarden commented 1 year ago

Does the cmdlet work ? because can't make work with -bodyparameter or -devicecategory, eveytime he result with an error `$Params = @{ DeviceCategory = @{ "DisplayName" = "$NewCategory"} } | ConvertTo-Json try {

Changer la category

Update-MgDeviceManagementManagedDevice -ManagedDeviceId $Device -BodyParameter $Params `

geoced commented 1 year ago

I cannot make it work either with the built-in cmdlets.

Update-MgBetaDeviceManagementManagedDevice -ManagedDeviceId $myIntuneDevice.Id -DeviceCategory $category
Update-MgBetaDeviceManagementManagedDevice : Cannot apply PATCH to navigation property 'deviceCategory' on entity type 'microsoft.management.services.api.managedDevice'.
Status: 400 (BadRequest)
ErrorCode: ModelValidationFailure
Date: 2023-10-03T17:24:51

Update-MgBetaDeviceManagementManagedDeviceCategory -ManagedDeviceId $myIntuneDevice.Id -Id $category.Id
Update-MgBetaDeviceManagementManagedDeviceCategory :
Status: 404 (NotFound)
ErrorCode: UnknownError
Date: 2023-10-03T17:03:16

The only way to make it work is like this:

$body = @{ '@odata.id' = "https://graph.microsoft.com/beta/deviceManagement/deviceCategories/$($category.Id)" }
Invoke-MgGraphRequest -Method PUT -Uri "beta/deviceManagement/managedDevices/$(myIntuneDevice.Id)/deviceCategory/`$ref" -Body $body
SamSepiolWarden commented 4 months ago

This one work for me :

Update-MgBetaDeviceManagementManagedDeviceCategory -ManagedDeviceId $Device -BodyParameter $BodyParams

With the new category in the body parameter