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

ManagedDevices enableLostMode not working #84

Closed MattFroud closed 4 years ago

MattFroud commented 4 years ago

Hi,

I am trying to use the following code to Enable Lost Mode on an Intune Managed iOS Device

$Json = @"
     "message": "If found please kindly call the number below...",
     "phoneNumber": "example number",
     "footer": "example footer text"
"@
Invoke-MSGraphRequest -Url https://graph.microsoft.com/beta/deviceManagement/managedDevices('$DeviceId')/enableLostMode -HttpMethod POST -Content $Json

On doing so I receive the error at the end of this post... I have extrapulated the same code from my script and run it via Graph Explorer and it works fine. I can use other command such as remoteLock, setDeviceName via the PowerShell SDK sucessfully, but not enableLostMode for some reason? Is this a known issue with the SDK or am I doing something wrong?

Many thanks, Matt

Invoke-MSGraphRequest : 400 Bad Request
{
  "error": {
    "code": "BadRequest",
    "message": "{\r\n  \"_version\": 3,\r\n  \"Message\": \"An error has occurred - Operation ID (for customer support): 00000000-0000-0000-0000-000000000000 - Activity 
ID: 5fec3519-7088-4a16-b308-99d501190932 - Url: https://fef.msub02.manage.microsoft.com/DeviceFE/StatelessDeviceFEService/deviceManagement/managedDevices%28%27xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx%27%29/microsoft.management.services.api.enableLostMode?api-version=5020-04-20\",\r\n  \"CustomApiErrorPhrase\": \"\",\r\n  \"RetryAfter\": 
null,\r\n  \"ErrorSourceService\": \"\",\r\n  \"HttpHeaders\": \"{}\"\r\n}",
    "innerError": {
      "date": "2020-06-17T13:09:55",
      "request-id": "5fec3519-7088-4a16-b308-99d501190932"
    }
  }
}
At line:13 char:29
+ ...             Invoke-MSGraphRequest -Url $GraphUri -HttpMethod $GraphMe ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ConnectionError: (@{Request=; Response=}:PSObject) [Invoke-MSGraphRequest], HttpRequestException
    + FullyQualifiedErrorId : PowerShellGraphSDK_HttpRequestError,Microsoft.Intune.PowerShellGraphSDK.PowerShellCmdlets.InvokeRequest
MattFroud commented 4 years ago

Hi,

I am trying to use the following code to Enable Lost Mode on an Intune Managed iOS Device

$Json = @"
     "message": "If found please kindly call the number below...",
     "phoneNumber": "example number",
     "footer": "example footer text"
"@
Invoke-MSGraphRequest -Url https://graph.microsoft.com/beta/deviceManagement/managedDevices('$DeviceId')/enableLostMode -HttpMethod POST -Content $Json

On doing so I receive the error at the end of this post... I have extrapulated the same code from my script and run it via Graph Explorer and it works fine. I can use other command such as remoteLock, setDeviceName via the PowerShell SDK sucessfully, but not enableLostMode for some reason? Is this a known issue with the SDK or am I doing something wrong?

Many thanks, Matt

Invoke-MSGraphRequest : 400 Bad Request
{
  "error": {
    "code": "BadRequest",
    "message": "{\r\n  \"_version\": 3,\r\n  \"Message\": \"An error has occurred - Operation ID (for customer support): 00000000-0000-0000-0000-000000000000 - Activity 
ID: 5fec3519-7088-4a16-b308-99d501190932 - Url: https://fef.msub02.manage.microsoft.com/DeviceFE/StatelessDeviceFEService/deviceManagement/managedDevices%28%27xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx%27%29/microsoft.management.services.api.enableLostMode?api-version=5020-04-20\",\r\n  \"CustomApiErrorPhrase\": \"\",\r\n  \"RetryAfter\": 
null,\r\n  \"ErrorSourceService\": \"\",\r\n  \"HttpHeaders\": \"{}\"\r\n}",
    "innerError": {
      "date": "2020-06-17T13:09:55",
      "request-id": "5fec3519-7088-4a16-b308-99d501190932"
    }
  }
}
At line:13 char:29
+ ...             Invoke-MSGraphRequest -Url $GraphUri -HttpMethod $GraphMe ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ConnectionError: (@{Request=; Response=}:PSObject) [Invoke-MSGraphRequest], HttpRequestException
    + FullyQualifiedErrorId : PowerShellGraphSDK_HttpRequestError,Microsoft.Intune.PowerShellGraphSDK.PowerShellCmdlets.InvokeRequest
MattFroud commented 4 years ago

After removing the footer parameter from the Json content, it now seems to work as expected! Rather odd, but am happy with this solution for my needs...

bab83 commented 3 years ago

Hi MattFroud, I am also facing the same problem with "enableLostMode". However, it's still not working after removing the footer. Could you please help me to provide exact code which you tried? Greatly appreciated. Thanks!