Skip to content

Script to Sync Windows Devices in Microsoft Graph

Windows Device Synchronization Script for Microsoft Graph

Section titled “Windows Device Synchronization Script for Microsoft Graph”

This PowerShell script connects to Microsoft Graph and automates the synchronization process for all managed Windows devices across your organization. The script provides real-time feedback during the synchronization process.


FunctionDescriptionBusiness Value
Tenant AuthenticationPrompts for Tenant ID and connects with required scopesSecure, tenant-specific access to device management
Device DiscoveryRetrieves all managed Windows devicesComprehensive device inventory and targeting
Bulk SynchronizationSends sync requests to all Windows devicesEnsures up-to-date device status and policies
Progress TrackingDisplays device count and sync progressReal-time monitoring and visibility

  • Prompts administrator for Tenant ID or primary domain
  • Establishes connection with DeviceManagementManagedDevices.ReadWrite.All and DeviceManagementManagedDevices.PrivilegedOperations.All scopes
  • Ensures proper permissions for device synchronization operations
  • Retrieves all managed devices from Microsoft Graph
  • Filters specifically for Windows operating system devices
  • Provides count of discovered devices for verification
  • Iterates through each discovered Windows device
  • Sends synchronization request using Sync-MgDeviceManagementManagedDevice
  • Displays progress for each device being synchronized

Terminal window
$TenantId = Read-Host "Please enter Tenant Id or Primary domain"
$Scopes = "DeviceManagementManagedDevices.ReadWrite.All, DeviceManagementManagedDevices.PrivilegedOperations.All"
Connect-MgGraph -TenantId $TenantId -Scopes $Scopes
$Devices = Get-MgDeviceManagementManagedDevice -All | Where-Object {$_.operatingSystem -eq 'Windows'}
Write-host " Number of Devices found: $($Devices.id.Count)" -ForegroundColor cyan
Foreach ($Device in $Devices) {
$DeviceId = $Device.id
Sync-MgDeviceManagementManagedDevice -ManagedDeviceId $DeviceId
Write-Host "Sending Sync request to Device $($Device.deviceName)" -ForegroundColor Yellow
}

Ideal for: IT administrators managing Windows device fleets with Microsoft Intune

Use Cases:

  • Force device policy updates
  • Troubleshooting device connectivity issues
  • Ensuring compliance across device fleets
  • Post-deployment synchronization verification

  • Microsoft Graph PowerShell SDK installed
  • Global Administrator or Intune Administrator role
  • Appropriate API permissions for device management
  • Windows devices enrolled in Microsoft Intune

Note: This script processes devices sequentially. For large device fleets, consider running during off-peak hours to minimize impact on user experience.