top of page
  • Writer's pictureGareth Oxendine

Sync Intune Devices using a PowerShell Script

Updated: Sep 15

This article provides you with an adjustable PowerShell script template that, when run, will force an MDM sync with Intune. What was a tedious and manual task in the portal, now only takes seconds!



Table of Contents


Prerequisites

  1. Both you and your application (PowerShell) will need the appropriate MgGraph permissions. You will most likely already have the appropriate Entra role (ex. Intune Administrator). You'll need to grant delegated consent for your enterprise application (Microsoft Graph PowerShell) in Entra ID applications for the three scopes below. You can either grant consent beforehand or interactively when you run the script.

    1. DeviceManagementManagedDevices.PrivilegedOperations.All

    2. DeviceManagementManagedDevices.ReadWrite.All

    3. DeviceManagementManagedDevices.Read.All

  2. Install the Microsoft.Graph.DeviceManagement module on the machine running the script. Use the following command to install it: Install-Module Microsoft.Graph.DeviceManagement


The Script


Step 1: Choose the Device Properties for the Filter

A crucial part of the script is choosing which Intune devices to sync. The way to choose devices is by using the devices' properties to create a filter. In one of my example script templates,  I use the DeviceName and Model properties.


Before we look at the script, let's see what kind of device properties are returned when querying a device using the following MgGraph PowerShell cmdlet: Get-MgDeviceManagementManagedDevice.


Below are most of the properties you can use when creating a filter. I've either removed sensitive data or replaced it with hashtags (#).

Step 2: Modify and Run the Script

Now that we know which properties are available to use, we can use them to create and execute the script. Below are some example use cases.


Example 1: Sync Specific Devices by using a Filter

In the example below, the script will grab all devices that match a device name and match a specific model. If your company uses a naming convention, this script will be really useful.

Example 2: Sync All Devices

In the example below, the script will try to sync every device in your Intune (Endpoint Manager) environment.




Cover Image provided by Freepik.

337 views0 comments

Comments


Recent Posts

Like this Article?

If this information was helpful, we want to know!

Leave a like by clicking the heart at the bottom of the page. 

Next Coffee on You?

We hope this article was helpful to you! If so, want to send a donation as a form of thanks? Just click the coffee cup!  :)

bottom of page