Scenario: You want a script that will remove all mobile devices older than 180 days. You also want to report the CAS Mailboxes that have a mobile device partnership and the list of mobile devices removed.
Scriptlets:
Here are the commands broken down by output type:
#Collect CasMailboxes with Mobile Devices $cas = Get-CASMailbox -ResultSize unlimited –Filter {(HasActiveSyncDevicePartnership -eq $true)} | Select -expandproperty Identity #Export a List of Cas Mailboxes $cas | Sort | Export-csv C:tempCASmailbox.csv #Collect devices older than 180 days old $device = @() $cas | sort | %{ "Checking $_" $device += Get-MobileDeviceStatistics -Mailbox $_ | Where-Object {$_.LastSuccessSync -le ((Get-Date).AddDays(“-180”))} } #Export-csv Stale Devices $Device | Export-csv C:tempStaleDevices.csv #Remove Mobile Devices $Device | Remove-mobiledevice -confirm:$false