microsoftgraph / powershell-intune-samples

This repository of PowerShell sample scripts show how to access Intune service resources. They demonstrate this by making HTTPS RESTful API requests to the Microsoft Graph API from PowerShell.
MIT License
1.32k stars 649 forks source link

Bad request when trying delete a device #45

Closed SRE93 closed 6 years ago

SRE93 commented 6 years ago

Hey, when trying to delete a device from intune through invoke-deviceaction got a bad request error:

Invoke-DeviceAction -DeviceID b05dcb23-0a67-4971-864d-59981906640d -Delete

WARNUNG: A deletion of a device will only work if the device has already had a retire or wipe request sent to the device...

Are you sure you want to delete this device? Y or N?
y
Response content:
{
  "error": {
    "code": "BadRequest",
    "message": "{\r\n  \"_version\": 3,\r\n  \"Message\": \"An error has occurred - Operation ID (for customer support): 00000000-0000-0000-0000-000000
000000 - Activity ID: 5e320693-d3c9-466c-9767-05e65fd74269 - Url: https://fef.amsub0102.manage.microsoft.com/DeviceFE/StatelessDeviceFEService/deviceMa
nagement/managedDevices%28%27b05dcb23-0a67-4971-864d-59981906640d%27%29?api-version=5018-03-23\",\r\n  \"CustomApiErrorPhrase\": \"\",\r\n  \"RetryAfte
r\": null,\r\n  \"ErrorSourceService\": \"\",\r\n  \"HttpHeaders\": \"{}\"\r\n}",
    "innerError": {
      "request-id": "5e320693-d3c9-466c-9767-05e65fd74269",
      "date": "2018-05-24T14:24:43"
    }
  }
}
Invoke-DeviceAction : Request to https://graph.microsoft.com/Beta/deviceManagement/managedDevices('b05dcb23-0a67-4971-864d-59981906640d') failed with 
HTTP Status BadRequest Bad Request
In Zeile:1 Zeichen:1
+ Invoke-DeviceAction -DeviceID b05dcb23-0a67-4971-864d-59981906640d -D ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-DeviceAction
mihaiLucian commented 6 years ago

Hey, does that device still exists? If you do a GET to https://graph.microsoft.com/Beta/deviceManagement/managedDevices/b05dcb23-0a67-4971-864d-59981906640d Do you receive the information about that device?

Bad requests are usually triggered when the resource that you are trying to access does not exist. I believe that device is already deleted and that is why you can't delete it any more.

SRE93 commented 6 years ago

Hey, device is still present in Azure Intune Portal and when using

Invoke-RestMethod -uri https://graph.microsoft.com/Beta/deviceManagement/managedDevices/b05dcb23-0a67-4971-864d-59981906640d -Headers $authToken

id                                        : b05dcb23-0a67-4971-864d-59981906640d
...

Additionally: The devices are macOS devices registered by Jamf Cloud relationship between Intune and Jamf Pro.

davefalkus commented 6 years ago

It looks like the way the delete is called has been updated in the beta endpoint, I will update the sample script.

davefalkus commented 6 years ago

Hi @dernettemann118

Apologies for the late response on this, does the delete work if its a non MacOS devices registered by Jamf? I looked at the sample again and the call in the script is correct.

Another question is if you look at the MacOS device in the UI is the delete option available?

Thanks

Dave

davefalkus commented 6 years ago

Hi @dernettemann118, if you have an update here please reopen the issue.