Endpoint Security Complete

Expand all | Collapse all

Script to remove stale Exchange ActiveSync device partnerships before Mobile Management implementation

  • 1.  Script to remove stale Exchange ActiveSync device partnerships before Mobile Management implementation

    Broadcom Employee
    Posted 04-08-2011 04:19 AM

    Hello,

    So, we decided to implement Mobile Management, but got a few surprises when we enabled EAS sync on the MM server. MM basically pulls in _every device_ that has ever synced over ActiveSync, and unless you've had a regime for deleting unused devices (which I suspect most Exchange admins don't) you're going to pull in a lot of stale data which in turn will eat up MM licenses.

    I wrote a small Powershell script to clear up stale ActiveSync device partnerships. It needs to be run on an Exchange Server that has the Mailbox Role installed, and the executing account needs to be an Exchange admin. The code starting from Get-CasMailbox needs to be on one line. To do a test run, just remove the " | Remove-ActiveSyncDevice" part at the end, then the script will simply list all partnerships that meet the criteria.

    ------------------------------------------------------

     

    # Powershell script to clear stale ActiveSync partnerships

    # Are Romøren, 07042011

    # Get all CAS-enabled mailboxes in Exchange organization and filter on LastSuccessSync

    # Must be run from an Exchange server with Mailbox Role installed, account needs Exchange administrative privileges

    # (Get-Date).AddDays("-7") - specify "older than"-parameter (current example will remove all partnerships older than 1 week)

     

    Get-CASMailbox -ResultSize unlimited -Filter{(HasActiveSyncDevicePartnership -eq $true) -AND (name -notlike "cas_*") -AND (name -notlike "DiscoverysearchMailbox*")} | ForEach {Get-ActiveSyncDeviceStatistics -Mailbox:$_.Identity | Where-Object {$_.LastSuccessSync -le (Get-Date).AddDays("-7")}} | Remove-ActiveSyncDevice

    ------------------------------------------------------



  • 2.  RE: Script to remove stale Exchange ActiveSync device partnerships before Mobile Management implementation

    Broadcom Employee
    Posted 04-20-2011 11:53 AM

    Nicely done!  Appreciate the tip.