1

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}

Joseph
  • 293
  • 2
  • 7
  • 14
  • why did you wish to perform this step? Normally this action is performed automatically as mentioned for example [here](https://4sysops.com/archives/error-with-your-new-mobile-phone-partnership-how-to-manage-exchange-device-limits/). – BastianW Apr 17 '17 at 19:02
  • I tried the throttling policies, only problem is I get "New-ThrottlingPolicy : The term 'New-ThrottlingPolicy' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.". I had been removing manually in the past. – Joseph Apr 20 '17 at 16:09
  • The New-ThrottlingPolicy is blocked on ExchangeOnline ... only Microsoft can use that, see [here](https://4sysops.com/archives/error-with-your-new-mobile-phone-partnership-how-to-manage-exchange-device-limits/). But Microsoft makes sure that there environment isn´t filled with multiple older devices and they are auto deleted older entries on there own with that policy. However not after 3 days. They allow a longer inactive time here. – BastianW Apr 20 '17 at 17:14
  • Funny. I noticed that was only available in on-prem just a moment ago. What about a way to forcibly remove old devices manually such as the one I posted? – Joseph Apr 20 '17 at 17:21
  • try to use Confirm:$false – BastianW Apr 20 '17 at 17:34

1 Answers1

1

Try the confirm option:

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 -Confirm:$false}
BastianW
  • 2,868
  • 4
  • 20
  • 34