Site icon Franky's Web

Exchange 2010: Find old ActiveSync partnerships

Over time, users often accumulate many old ActiveSync partnerships that have not been used for a long time. The following script can be used to find old ActiveSync partnerships:

$LastSuccessSyncBefore = 180
$FirstSyncDateBefore = 180

#--------------------------------------------------------------------------------------
$today = get-date
$lastsyncdate = $today.AddDays(-$LastSuccessSyncBefore)
$firstsyncdate = $today.AddDays(-$FirstSyncDateBefore)

$results =@() 
$activesyncdevicelist = Get-ActiveSyncDevice -resultsize unlimited | where {$_.FirstSyncTime -le $firstsyncdate}

 foreach ($activesyncdevice in $activesyncdevicelist)
  {
   $asdevstats = $activesyncdevice | Get-ActiveSyncDeviceStatistics | where {$_.LastSuccessSync -le $lastsyncdate}
   if ($asdevstats)
   {
   $UserdisplayName = $activesyncdevice.UserDisplayName
   $username = (get-mailbox $userdisplayname).Name
   $Devicemodel = $activesyncdevice.devicemodel
   $devicetype = $activesyncdevice.devicetype
   $firstsync = $asdevstats.FirstSyncTime
   $lastsync = $asdevstats.LastSuccessSync

   $results += new-object PSObject -property @{UserName="$UserName";DeviceModel="$devicemodel";DeviceType="$devicetype";FirstSync="$firstsync";LastSync="$lastsync"}
   }
 }
 
$results | ft -autosize

Simply change the values for LastSuccessSyncBefore (last successful synchronization XX days ago) and FirstSyncDateBefore (first synchronization XX days ago), or leave it at 180 days.

The script can easily be extended to display additional information or to automatically delete the partnerships.

Exit mobile version