top of page
Writer's pictureGareth Oxendine

Force Sync Devices to Intune using a PowerShell Script

Updated: 3 days ago


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.

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

    2. 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):

  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

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


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, Get-MgDeviceManagementManagedDevice. For privacy, I've either removed sensitive values or replaced them with hashtags (#).


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!



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.

2,243 views0 comments

Related Posts

See All

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. 

Follow us on LinkedIn!

We'd like to invite you to follow us on LinkedIn! Click the icon to follow.

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