After our migration to Office365 and ExchangeOnline, coming from Exchange 2010, my script to remove mobile devices seems to just generate a watson dump, kick me out and fail. Does anyone have any modifications that work?
Original script (modified to show mobiledevice instead of activesyncdevice)
$DevicesToRemove = Get-MobileDevice -result unlimited | Get-MobileDeviceStatistics | where {$_.LastSuccessSync -le (Get-Date).AddDays("-3")}
$DevicesToRemove | foreach-object {Remove-MobileDevice ([string]$_.Guid) -confirm:$false}
Another script I've tried, which does try to remove, but asks to confirm every one!
Get-CASMailbox -ResultSize unlimited –Filter {(HasActiveSyncDevicePartnership -eq $true) -AND (name -notlike "cas*") -AND (name -notlike "DiscoverysearchMailbox*")} | ForEach {Get-MobileDeviceStatistics -Mailbox $_.Identity | Where-Object {$_.LastSuccessSync -le ((Get-Date).AddDays("-14"))} | Remove-MobileDevice}