A very quick script today but one which I use regularly. There is nothing worse than deploying a new policy or app and then waiting for the machines to check-in, especially if you’ve just missed a cycle.
This script runs through all devices and nudges them along.
As usual it’s on GitHub and PS Gallery
Install-Script -Name SyncAllIntuneDevices
Once logged in and authenticated to MS Graph, it’s fairly basic:
A function to sync a device:
function SyncDevice {
param
(
$DeviceID
)
$Resource = "deviceManagement/managedDevices('$DeviceID')/syncDevice"
$uri = "https://graph.microsoft.com/Beta/$($resource)"
write-verbose $uri
Write-Verbose "Sending sync command to $DeviceID"
Invoke-MSGraphRequest -Url $uri -HttpMethod POST
}
Wrapped in a loop to go through the devices
$graphApiVersion = "beta"
$Resource = "deviceManagement/managedDevices"
$uri = "https://graph.microsoft.com/$graphApiVersion/$Resource"
$devices = (Invoke-MSGraphRequest -Url $uri -HttpMethod Get).Value
foreach ($device in $devices) {
SyncDevice -Deviceid $device.id
$devicename = $device.deviceName
write-host "Sync sent to $devicename"
}
Simple, but does the job!
Stops at 1000, you know how to work around that?
I’ve just added a new version to Github with support for pagination, can you see if that works?