Use PowerShell and MS Graph to locate an Intune device
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
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:
2 commentaires
Of course, no company will ever use this to track their employees... (。_。)
You can also search for an individual device like so:
Get-IntuneManagedDevice -Filter "deviceName eq '$DeviceName'"
Enregistrer un commentaire