Locate device using Microsoft Graph and Invoke-RestMethod with Intune

This post is just for fun haha.

We will use Graph API and Powershell to remotely run the remote action to locate a device. And for our curiosity, we will open a map to locate the device automatically.

Remotely locate the device

First, you need the Intune device id. You get this id either in the Intune console or by creating a prompt for the admin so he can put the id in it.

Let’s go for authentication (i use the MSAL.ps module).
Then, you use Invoke-RestMethod with a POST method to run an action. No get action for now.

I suggest you to wait 15 min or either creating a loop until the status changed from « pending » to « done » using this API as below : https://graph.microsoft.com/beta/deviceManagement/manageddevices/$id?$select=deviceActionResults

Note that the end-user will get a notification on his device such as :

Yes, i’m french. Don’t mind the watermark.

Let’s get the location results

Now we have the confirmation that the remote action is done, let’s collect the results.

Ok good, now we isolate the coordonates.

And just for fun, let’s search on the internet the location using any website you like :

« Et voilà ! »

Laisser un commentaire