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

Update-MgDeviceManagementManagedDeviceCategory does not update the device category as intended for Intune managed devices

Open SubhamV opened this issue 1 year ago • 4 comments

Thanks for reporting the bug. Please ensure you've gone through the following checklist before opening an issue:

  • Make sure you can reproduce this issue using the latest released version of Microsoft.Graph or Microsoft.Graph.Beta.
  • Please search the existing issues to see if there has been a similar issue filed.
  • For issues related to authentication and service errors, please refer to our troubleshooting guide. For service issues, please open a question at https://developer.microsoft.com/graph/support.

Describe the bug

Aim: Update device category of Intune managed devices via the Microsoft.Graph.DeviceManagement library using PowerShell.

I found the following cmdlet: Update-MgDeviceManagementManagedDevicesCategory which should (in theory) update the device category. Firstly, I verified that the correct device details are showing up using the cmdlet: Get-MgDeviceManagementManagedDeviceCategory -managedDeviceId <Intune device Id>. This worked and returned the following output.

image

However, when I use the Update command, it fails with error "No OData route exists."

Command executed: Update-MgDeviceManagementManagedDeviceCategory -managedDeviceId <Intune device Id> -DisplayName "Contoso" Output: Update-MgDeviceManagementManagedDeviceCategory : No OData route exists that match template ~/singleton/navigation/key/navigation with http verb PATCH for request /DeviceFE/StatelessDeviceFEService/deviceManagem ent/managedDevices('fd7c3a2b-4c26-448d-9498-4770a84a176b')/deviceCategory. Status: 400 (BadRequest) ErrorCode: No method match route template Date: 2023-11-20T09:46:38 Headers: Transfer-Encoding : chunked Vary : Accept-Encoding Strict-Transport-Security : max-age=31536000 request-id : client-request-id : x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"South India","Slice":"E","Ring":"2","ScaleUnit":"001","RoleInstance":"MA1PEPF0000272F"}} Date : Mon, 20 Nov 2023 09:46:38 GMT At line:1 char:1

  • Update-MgDeviceManagementManagedDeviceCategory -managedDeviceId fd7c3 ...
  •   + CategoryInfo          : InvalidOperation: ({ ManagedDevice...eviceCategory }:<>f__AnonymousType90`2) [Update-MgD
     evice..._UpdateExpanded], Exception
      + FullyQualifiedErrorId : No method match route template,Microsoft.Graph.PowerShell.Cmdlets.UpdateMgDeviceManageme
     ntManagedDeviceCategory_UpdateExpanded
    
    

Running the Graph query /deviceManagement/managedDevices('fd7c3a2b-4c26-448d-9498-4770a84a176b')/deviceCategory in Graph Explorer returns successful result.

To Reproduce Steps to reproduce the behavior:

  1. Connect to Graph API. Execute Connect-MgGraph
  2. Execute Update-MgDeviceManagementManagedDeviceCategory -managedDeviceId <Intune device Id> -DisplayName "<Category name>"

Expected behavior

As per documentation, we should be able to update the device category display name.

Debug Output

DEBUG: [CmdletBeginProcessing]: - Update-MgDeviceManagementManagedDeviceCategory begin processing with parameterSet
'UpdateExpanded'.

Confirm
Continue with this operation?
[Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"): a
DEBUG: [Authentication]: - AuthType: 'Delegated', TokenCredentialType: 'InteractiveBrowser', ContextScope:
'CurrentUser', AppName: 'Microsoft Graph Command Line Tools'.
DEBUG: [Authentication]: - Scopes: [Device.ReadWrite.All, DeviceManagementManagedDevices.Read.All,
DeviceManagementManagedDevices.ReadWrite.All, DeviceManagementServiceConfig.ReadWrite.All, Group.ReadWrite.All, openid,
 profile, User.Read, email].

Confirm
Are you sure you want to perform this action?
Performing the operation "Update-MgDeviceManagementManagedDeviceCategory_UpdateExpanded" on target "Call remote 'PATCH
/deviceManagement/managedDevices/{managedDevice-id}/deviceCategory' operation".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): a
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
PATCH

Absolute Uri:
https://graph.microsoft.com/v1.0/deviceManagement/managedDevices/fd7c3a2b-4c26-448d-9498-4770a84a176b/deviceCategory

Headers:
FeatureFlag                   : 00000043
Cache-Control                 : no-store, no-cache
User-Agent                    : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.22631;
en-US),PowerShell/5.1.22621.2506
Accept-Encoding               : gzip
SdkVersion                    : graph-powershell/2.9.0
client-request-id             : <redacted>

Body:
{
  "displayName": "Contoso"
}

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
BadRequest

Headers:
Transfer-Encoding             : chunked
Vary                          : Accept-Encoding
Strict-Transport-Security     : max-age=31536000
request-id                    : <redacted>
client-request-id             : <redacted>
x-ms-ags-diagnostic           : {"ServerInfo":{"DataCenter":"South
India","Slice":"E","Ring":"2","ScaleUnit":"000","RoleInstance":"MA1PEPF000012F3"}}
Date                          : Mon, 20 Nov 2023 09:59:32 GMT

Body:
{
  "error": {
    "code": "No method match route template",
    "message": "No OData route exists that match template ~/singleton/navigation/key/navigation with http verb PATCH
for request
/DeviceFE/StatelessDeviceFEService/deviceManagement/managedDevices('fd7c3a2b-4c26-448d-9498-4770a84a176b')/deviceCatego
ry.",
    "innerError": {
      "date": "2023-11-20T09:59:32",
      "request-id": "<redacted>",
      "client-request-id": "<redacted>"
    }
  }
}

Confirm
No OData route exists that match template ~/singleton/navigation/key/navigation with http verb PATCH for request
/DeviceFE/StatelessDeviceFEService/deviceManagement/managedDevices('fd7c3a2b-4c26-448d-9498-4770a84a176b')/deviceCatego
ry.

Status: 400 (BadRequest)
ErrorCode: No method match route template
Date: 2023-11-20T09:59:32

Headers:
Transfer-Encoding             : chunked
Vary                          : Accept-Encoding
Strict-Transport-Security     : max-age=31536000
request-id                    : <redacted>
client-request-id             : <redacted>
x-ms-ags-diagnostic           : {"ServerInfo":{"DataCenter":"South
India","Slice":"E","Ring":"2","ScaleUnit":"000","RoleInstance":"MA1PEPF000012F3"}}
Date                          : Mon, 20 Nov 2023 09:59:32 GMT

[Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"): a
Update-MgDeviceManagementManagedDeviceCategory : No OData route exists that match template
~/singleton/navigation/key/navigation with http verb PATCH for request /DeviceFE/StatelessDeviceFEService/deviceManagem
ent/managedDevices('fd7c3a2b-4c26-448d-9498-4770a84a176b')/deviceCategory.
Status: 400 (BadRequest)
ErrorCode: No method match route template
Date: 2023-11-20T09:59:32
Headers:
Transfer-Encoding             : chunked
Vary                          : Accept-Encoding
Strict-Transport-Security     : max-age=31536000
request-id                    : <redacted>
client-request-id             : <redacted>
x-ms-ags-diagnostic           : {"ServerInfo":{"DataCenter":"South
India","Slice":"E","Ring":"2","ScaleUnit":"000","RoleInstance":"MA1PEPF000012F3"}}
Date                          : Mon, 20 Nov 2023 09:59:32 GMT
At line:1 char:1
+ Update-MgDeviceManagementManagedDeviceCategory -managedDeviceId fd7c3 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: ({ ManagedDevice...eviceCategory }:<>f__AnonymousType90`2) [Update-MgD
   evice..._UpdateExpanded], Exception
    + FullyQualifiedErrorId : No method match route template,Microsoft.Graph.PowerShell.Cmdlets.UpdateMgDeviceManageme
   ntManagedDeviceCategory_UpdateExpanded
DEBUG: [CmdletEndProcessing]: - Update-MgDeviceManagementManagedDeviceCategory end processing.

Module Version

Script 2.9.0 Microsoft.Graph.Authentication Script 2.9.0 Microsoft.Graph.DeviceManagement

Environment Data

PSVersion 5.1.22621.2506 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.22621.2506 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context Discussed internally with Microsoft SME (markstan) and he confirmed that this needs to be reported on why the command fails with error "No OData route exists" when the same can be queried with Graph explorer or by using the invoke commands.

SubhamV avatar Nov 20 '23 10:11 SubhamV

Subham, thanks for your assistance on this issue.

PJMarcum avatar Nov 20 '23 16:11 PJMarcum

@SubhamV ... I just ran into this problem trying to update the Category of Devices using: Update-MgDeviceManagementManagedDeviceCategory -ManagedDeviceId $IntuneDevice.Id -BodyParameter $Body

I get the following Error... Update-MgDeviceManagementManagedDeviceCategory_Update:

Status: 404 (NotFound) ErrorCode: UnknownError

When I run with -Debug I notice the following call is being made... Absolute Uri: https://graph.microsoft.com/v1.0/deviceManagement/managedDevices/8c7162e5-204a-40b1-8d26-dc9f1bdf422c/deviceCategory

Body: { "@odata.id": "https://graph.microsoft.com/v1.0/deviceManagement/deviceCategories/fc7ac0e4-f88a-4935-8275-54591fbb158a" }

AFAIK, the Uri looks wrong to me, shouldn't the Absolute Uri end with /$Ref when trying to update a ref-property like Category? ... or is there something wrong with my Body?

The full -Debug response below... --- Debug -- DEBUG: ============================ HTTP REQUEST ============================

HTTP Method: PATCH

Absolute Uri: https://graph.microsoft.com/v1.0/deviceManagement/managedDevices/8c7162e5-204a-40b1-8d26-dc9f1bdf422c/deviceCategory

Headers: FeatureFlag : 00000043 Cache-Control : no-store, no-cache User-Agent : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.22631; en-SE),PowerShell/7.4.2 Accept-Encoding : gzip SdkVersion : graph-powershell/2.17.0 client-request-id : 453e1211-9fd2-490c-b89c-f67df074e5f8

Body: { "@odata.id": "https://graph.microsoft.com/v1.0/deviceManagement/deviceCategories/fc7ac0e4-f88a-4935-8275-54591fbb158a" }

DEBUG: ============================ HTTP RESPONSE ============================

Status Code: NotFound

Headers: Vary : Accept-Encoding Strict-Transport-Security : max-age=31536000 request-id : b56e8ffc-0254-4d41-bfed-39ab8aab214f client-request-id : 453e1211-9fd2-490c-b89c-f67df074e5f8 x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"Sweden Central","Slice":"E","Ring":"3","ScaleUnit":"002","RoleInstance":"GV3PEPF00000B44"}} Date : Mon, 22 Apr 2024 08:34:42 GMT

Body: { "error": { "code": "UnknownError", "message": "", "innerError": { "date": "2024-04-22T08:34:42", "request-id": "b56e8ffc-0254-4d41-bfed-39ab8aab214f", "client-request-id": "453e1211-9fd2-490c-b89c-f67df074e5f8" } } }

KentNordstrom avatar Apr 22 '24 08:04 KentNordstrom

To follow up on my last comment and to verify the finding...

If I do the following... $Uri https://graph.microsoft.com/v1.0/deviceManagement/managedDevices/8c7162e5-204a-40b1-8d26-dc9f1bdf422c/deviceCategory/$Ref

And then use Invoke-MgGraphRequest instead... Invoke-MgGraphRequest -Uri $Uri -Body $Body -Method PUT -ContentType "Application/JSON"

It works just fine to update the Category of the Device as intended.

KentNordstrom avatar Apr 22 '24 09:04 KentNordstrom