question

Babbab-7242 avatar image
0 Votes"
Babbab-7242 asked Crystal-MSFT commented

How to setup lost mode in the Intune portal for the device using Graph API by Powershall script

Any option to enable lost mode in the Intune portal for the device using Graph API by Powershall script

windows-server-powershellmem-intune-generalmem-intune-graph
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Crystal-MSFT avatar image
0 Votes"
Crystal-MSFT answered Crystal-MSFT commented

@Babbab-7242, This is from Intune support. For your request, maybe you can try the following scripts:

 import-Module Microsoft.Graph.Intune #import intune module
    
 Update-MSGraphEnvironment -SchemaVersion beta #set schema version as beta
 Connect-MSGraph  #connect to MS grasp
    
 $body = @{'message' = 'Please Contact me';
           'phoneNumber' = '1111111111';
       'footer'= 'Test'}
 $bodyobj = New-Object -TypeName PSObject -Property $body
 Invoke-MSGraphRequest -Url /deviceManagement/managedDevices/5cb***b603ea/enableLostMode -Content $bodyobj -HttpMethod POST

Note: Please change the related infromation as your reference.

Here is a link related with lost mode in Graph API for the referrence:
https://docs.microsoft.com/en-us/graph/api/intune-devices-manageddevice-enablelostmode?view=graph-rest-beta

Hope it can help.


If the response is helpful, please click "Accept Answer" and upvote it.
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.



· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Looks to be working. However, I am getting below error message. Any insights? Thanks!

Invoke-MSGraphRequest : 400 Bad Request
{
"error": {
"code": "BadRequest",
"message": "Resource not found for the segment 'enableLostMode'.",
"innerError": {
"date": "2021-03-25T16:51:01",
"request-id": "988dc8bf-db90-47f9-83a9-6a9435330a81",
"client-request-id": "988dc8bf-db90-47f9-83a9-6a9435330a81"
}
}
}
At line:7 char:25

0 Votes 0 ·

@Babbab-7242, Based as I know, the 'enableLostMode' can only be run on some specific devices. Could you go to Intune portal and check if the function is enabled on the device:?
81698-image.png
https://docs.microsoft.com/en-us/mem/intune/remote-actions/device-lost-mode


0 Votes 0 ·
image.png (89.9 KiB)

I am able to enable/disable "Lost Mode" in the portal for the same device. However, if I run the Powershell command with Device ID, I am getting below error. Any insight for the "400 Bad Request" error? Thanks

Invoke-MSGraphRequest : 400 Bad Request
{
"error": {
"code": "BadRequest",
"message": "Resource not found for the segment 'enableLostMode'.",
"innerError": {
"date": "2021-03-29T16:23:21",
"request-id": "da95d20f-a8f1-4d8e-b8d5-c8589aee12a2",
"client-request-id": "da95d20f-a8f1-4d8e-b8d5-c8589aee12a2"
}
}
}
At line:1 char:1
+ Invoke-MSGraphRequest -Url /deviceManagement/managedDevices/bdc8423b- ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 Votes 0 ·
Show more comments