Sync all Intune devices via PowerShell
In our new team, all devices with a specific mobile OS are to be force synced, and the bulk device action is the method they use to do so. We performed the device sync for our mobile devices using PowerShell and Graph SDK rather than the traditional GUI bulk device action.
Firstly, we need to install the Graph Intune SDK
MSGraph can be used to sync all iOS devices via one PowerShell command as opposed to 100 at a time in the GUI. This is useful when we need to sync all iOS devices to force them into checking into Intune and picking up the latest iOS version and installing it, especially when we have a zero-day vulnerability identified
Once SDK is installed, we will connect with msgraph
It will ask us to login with our admin account
Once Authentication is successful, it will display the tenantID
Now we can initiate the command to sync either one or multiple devices
To get the specific device, we need to connect to the Intune managed device and then use the Get-IntuneManagedDevice cmdlet with the -Filter parameter.
Get-IntuneManagedDevice -Filter "contains(deviceName,’Sumit’s iphone’)"
After retrieving the device, we need to invoke the sync request using the Invoke-IntuneManagedDeviceSyncDevice cmdlet. The result can be piped if you want to make a one-liner.
Get-IntuneManagedDevice -Filter "contains(deviceName,' Sumit’s iphone ')" | Invoke-IntuneManagedDeviceSyncDevice”
Sync multiple devices.
The power of the Intune Powershell SDK can be leveraged to sync multiple devices. In order to sync all the devices, we need to start just as we did when we synced one device.
To get all the devices we want to sync, we need to use the Get-IntuneManagedDevice cmdlet and the -Filter parameter to get perhaps, iOS or Android devices.
To sync all the iOS devices
Get-IntuneManagedDevice -Filter "contains(operatingsystem, 'iOS')" | Get-MSGraphAllPages | Invoke-IntuneManagedDeviceSyncDevice
To sync all the Android devices
Get-IntuneManagedDevice -Filter "contains(operatingsystem, 'Android')" | Get-MSGraphAllPages | Invoke-IntuneManagedDeviceSyncDevice