Intune PowerShell Enable Lost Mode

Copper Contributor

Hi there,

I want to disable multiple devices (Apple Devices) in Intune. Particularly I want to put them in Enable Lost Mode = Enabled

Once the LostModeState = Disabled 

I am successfully able to Enable this state using this PowerShell Command

invoke-msGraphRequest -Url "/deviceManagement/managedDevices/$device.id/DisableLostMode -HTTPMethod POST

 

The command above is working just fine.

 

But when I use the same command to enable the Same devices it is not working neither I am getting any error message. I am using this command to enable the LostModeState

$message = 'test-disable'

invoke-msGraphRequest -Url "/deviceManagement/managedDevices/$device.id/EnableLostMode -HTTPMethod POST -Content $message

 

Thanks for your help

2 Replies

Hi @Ansari790,

if I undestood your question, you can try the following script:

# Authenticate to Microsoft Graph API
Connect-MSGraph

# Get the list of device IDs for the devices you want to enable Lost Mode on
$deviceIds = @("device_id1", "device_id2", "device_id3")

# Loop through each device ID and enable Lost Mode
foreach ($deviceId in $deviceIds) {
# Create the request body with the Lost Mode message
$body = @{
"message" = "Your Lost Mode message goes here"
} | ConvertTo-Json

# Send the request to enable Lost Mode for the device
Invoke-MSGraphRequest -Url "/deviceManagement/managedDevices/$deviceId/EnableLostMode" -Method Post -Body $body
}

The provided script goes through a list of device IDs and sends a request to enable Lost Mode for each device in the Intune environment. 

Just be sure that you have the necessary PowerShell modules, such as Microsoft.Graph.Intune and Microsoft.Graph.Authentication, installed and up to date.

Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

Kindest regards

Leon Pavesic

Hi Leon,

Thanks for the reply.

I am using the -Method POST and -Boby $body but this is not working
It is telling the Parameter cannot be found that matches 'Body' or 'Method'

I am using this script:

foreach ($Device in $Devices) {
$body = @{
"message" = "MyTest"
} | ConvertTo-Json

Invoke-MsGraphRequest -Url "/deviceManagement/managedDevices/$Device/EnableLostMode" -Content $body -HttpMethod POST
}

I am getting this error:
Invoke-MsGraphRequest : 404 Not Found
{"error":{"code":"ResourceNotFound","message":"Invalid version: devicemanagement","innerError":{"date":"2023-07-10T15:38:48","request-id":"94449

Any idea? Thanks