Recently in doing a device remediation exercise it was necessary to run some PowerShell code on a device via Intune – this is easily done using the built in scripts capability. There was however the requirement to trigger an Intune sync after performing the actions, so that the appropriate updated policies are then brought down to the device almost immediately, rather than having to wait for Intune to execute its sync on the next scheduled opportunity.
Well it turns out this is fairly straightforward to achieve, by putting the code below at the bottom of the PowerShell script. Yes – it turns out the Intune sync process is a scheduled task, and starting this scheduled task runs an Intune sync!
Get-ScheduledTask -TaskName “Schedule #3 created by enrollment client” | Start-ScheduledTask
Keep in mind I didn’t do any stress testing on this, so I don’t know how the Intune service would behave if you continually try and run syncs. However in this case doing an isolated additional sync appears to function as expected without any issues.