Bulk Retrieval and Removal of Teams Devices (from Azure AD and therefore Intune)
So my day job, at Poly, requires that I test a load of native Microsoft Teams devices – it’s a hard job, but somebody got to do it! 😉
This can throw into the mix some interesting scenarios, one of which is reaching the cap of maximum registered Intune devices (to a user), which by default is 15. This can be increased to 50, see here.
However I’m still seeing this threshold being reached which subsequently throws an Intune enrollment error – device cap reached.
The removal of devices via the Azure Active Directory web interface is great for removing a few devices, but anything more and it just falls down. But never fear PowerShell to the rescue!
First up I want to create a CSV that contains all devices that have not registered since December 31st 2019 (this date can obviously be modified to suit your needs)
$dt = [datetime]’2019/12/31’
Get-MsolDevice -all -LogonTimeBefore $dt | select-object -Property Enabled, DeviceId, DisplayName, DeviceTrustType, ApproximateLastLogonTimestamp | export-csv devicelist-olderthan-Dec-31-2019-summary.csv
This will create a CSV file with all devices, their IDs, names and last logon time.
Once you’ve pruned the CSV you can use this as a template to go ahead and perform bulk removal.
$list=import-csv devicelist-olderthan-Dec-31-2019-summary.csv
Foreach($device in $list){ Remove-MSOLDevice -DeviceId $device.DeviceId -force }
This can take some time to complete and once done you can always re-execute the first step to validate devices have been removed successfully.