Forum Discussion
Ansari790
Jul 10, 2023Copper Contributor
Intune PowerShell Enable Lost Mode
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 E...
LeonPavesic
Jul 10, 2023Silver Contributor
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
Shahrukh2150
Jul 10, 2023Copper Contributor
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
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