Loading...

Use PowerShell and MS Graph to locate an Intune device

2 A+ A-


In this post I will show you how to use PowerShell and MS Graph to locate an Intune device.


Prerequisites

You will first have to enable location on your device.

You can check it in the notification center as below:

You can enable it by clicking on it.

You can also enable it with PowerShell as below:


Locate device

Microsoft has added the possibility to locate an Intune device through the portal.

See the new alert from the what's new in Intune link.


For that, just go to a device and click on Locate device, as below:


Locate with PowerShell

Now let's do this with PowerShell.

1. You will first need to get the ID of the device. I will check device that has a specific name as below:

2. Then I will get the ID:

3. Now I will run the locate device action, as below:

4. The next step is to check device location result using below command:

5. The result is empty because you have to wait a bit.

6. On you device, you will get the below notification:

7. Now let's check again with PowerShell:

8. See below result:



Display in MAP and address 
Now let's see how to get address info with PowerShell and how to open a MAP with device location.
1. We will first get Latitude and Longitude
2. We will show location in MAPS, as below:
3. See below the result:

4. We will get full location as below:
5. See below the result:


Full script

I created a script allowing you to check location for a specific device and displays it in a MAP in your browser.

Display basic location
This will get location of a device and display basic info in PowerShell.
See the command to use: Invoke_LocateDevice.ps1 -Device_Name "TEST"

Display location in a MAP
This will get location of a device and display it in a MAP in your browser.
See the command to use: Invoke_LocateDevice.ps1 -Device_Name "TEST"

Get last location
This will get the last location of a device and display it in a MAP in your browser.
See the command to use: Invoke_LocateDevice.ps1 -Device_Name "TEST" -LastLocation -MAP

Display address
This will get the last location of a device and display it in a MAP in your browser.
See the command to use: Invoke_LocateDevice.ps1 -Device_Name "TEST" -Address


You can get the script by clicking on the GitHub picture below:


See below an overview:



slider 3776174808262866544

Enregistrer un commentaire

2 commentaires

Fred a dit…

Of course, no company will ever use this to track their employees... (。_。)

Trevor Jones a dit…

You can also search for an individual device like so:
Get-IntuneManagedDevice -Filter "deviceName eq '$DeviceName'"

Accueil item

Award

Learn KQL in one month

Sponsors

You want to support me ?

Mes articles en français

Books in French


Stats