top of page

Force Sync Devices to Intune using a PowerShell Script

  • Writer: Gareth Oxendine
    Gareth Oxendine
  • Jul 20, 2024
  • 2 min read

Updated: Mar 10

SUMMARY:

I love this script! It allows you to force multiple or all devices to check in with Intune simultaneously. What used to be a tedious and manual task in the portal, now only takes seconds!

Table of Contents


Prerequisites

The script uses Microsoft Graph PowerShell cmdlets, so the following prerequisites are needed:


  1. Both you and your application (PowerShell) will need the following MgGraph scopes (permissions): DeviceManagementManagedDevices.PrivilegedOperations.All, DeviceManagementManagedDevices.ReadWrite.All, DeviceManagementManagedDevices.Read.All.

  2. Adding Permissions for You: a quick way to ensure you have the appropriate permissions is to assign yourself the Intune Administrator role.

  3. Adding Permissions for PowerShell: when you run the script for the first time, you will be prompted to provide consent; select Accept (see the example below):

  4. 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

Here is the script template. Before running it, though, you'll need to modify it. See the steps below.

NOTE:

This a script you execute on a computer; it is not one you deploy using Intune.

Step 1: Choose the Device Properties for the Filter

A crucial part of the script is choosing which Intune devices to sync. You can create a filter for which devices to sync by using properties. For example, you can create a filter for devices based on 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 PowerShell command below (for privacy, I've either removed sensitive values or replaced them with hashtags #):

Get-MgDeviceManagementManagedDevice

The device properties are listed on the left with their example values on the right:

Now that we know which properties are available, we can use them to create and execute the script. Replace <insert device property> with the desired filter. For example, to sync all Windows devices, you would replace {<insert device property>} with {$_.OperatingSystem -eq "Windows"}.


Step 2: Run the Script

Once you've modified the script, it is ready to execute!

NOTE:

It may take up to 5 minutes for the device(s) to sync once you've run the script.

Below are some example scripts you can use:


Example 1: Sync Devices by Their Name and Model

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 environment.






Cover Image provided by Freepik.

Never Miss a Post. Subscribe Now!

Want to be notified whenever a new article is posted? Enter your email address and subscribe!

Thanks for submitting!

Donate to the Blog?

We hope the blog was helpful to you! If so, we'll take a donation as a form of thanks! :) 

© 2024 by DMTT. Powered and secured by Wix

$

Thank you for your donation!

bottom of page