Cannot delete devices from Intune using PS.

Oleg Tserkovnyuk 671 Reputation points
2024-04-12T13:34:34.59+00:00

Cannot delete devices from the Intune using PS.

To get devices I use Graph API (https://learn.microsoft.com/en-us/graph/api/intune-devices-manageddevice-list?view=graph-rest-1.0&tabs=http).

To delete I use https://learn.microsoft.com/en-us/graph/api/intune-devices-manageddevice-delete?view=graph-rest-1.0&tabs=http. The GrpahAPI expects parameter deviceId.

E.g.:

Invoke-MgGraphRequest -Method DELETE -Uri "v1.0/deviceManagement/managedDevices/$($ManagedDevice.id)"

Or

Remove-MgDeviceManagementManagedDevice -ManagedDeviceId $ManagedDevice.id

 

If I run any of these commands, they complete without errors but do not delete the device.

I tried to change one digit in device id and commands returned the error. So endpoint parses the id, not ignores it.

 

I analyzed what happens when I delete the device from the UI.

The system sends: DELETE to https://graph.microsoft.com/v1.0/devices/%Device_Object_Id%

And this is the problem. Object Id is visible only from the UI and not returned when I use the code from the first link.

E.g.

The device from the UI:User's image

When I load same device using PS, I get Device ID, but do not get Object ID.

If I delete this device from the UI, the system will send DELETE to https://graph.microsoft.com/v1.0/devices/aaaaaaaa-aaaa-aaaaa-8f83-fc0c3444cf31

If I run

Remove-MgDeviceManagementManagedDevice -ManagedDeviceId $DeviceID

nothing happens. No errors, and the device is not deleted.User's image

If I delete the device from UI it uses Object Id:User's image

Is this expected behavior or a bug? If the behavior is expected where I can find the object id?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,510 questions
Microsoft Intune
Microsoft Intune
A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.
5,570 questions
0 comments No comments
{count} votes

Accepted answer
  1. Crystal-MSFT 53,821 Reputation points Microsoft External Staff
    2024-04-15T02:38:21.47+00:00

    @Oleg Tserkovnyuk, Thanks for posting in Q&A. Based on my testing, I find the delete has some time delay. For the first I run the remove command, I find the device record still there.

    User's image

    But after waiting some time and run again, I find the device is removed.

    User's image

    And the device is removed in portal as well.

    User's image

    Please wait some time and try again to see if it can work.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.