Clear ActiveSync Stale Partnerships

Hi Readers,

Sharing a script that can be used to clear ActiveSync Stale Partnerships.

Define the number of days , for example:- for 1 month old partnerships to be removed

Enter 30

$days = (get-date).adddays(-30)

Download and extract the script from below link.

This script is useful in cleanup of old & stale partnerships.

https://gallery.technet.microsoft.com/scriptcenter/Clear-ActiveSync-Stale-2a459bd3

######################################################################################## 
#        This script  will Clear Activesync Partnerships that are  
#                older specified days 
 
#        Author: Vikas Sukhija 
#         Date:- 01/7/2015 
# 
######################################################################################## 
#Start-Transcript 
 
If ((Get-PSSnapin | where {$_.Name -match "Microsoft.Exchange.Management.PowerShell.E2010"}) -eq $null) 
{ 
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 
} 
 
#format Date 
 
$date = get-date -format d 
$date = $date.ToString().Replace(“/”, “-”) 
 
$days = (get-date).adddays(-30) 
 
$output = ".\logs\" + "Clearpartnership" + $date + "_.txt" 
 
$casm = get-casmailbox -resultsize unlimited | where {$_.HasActiveSyncDevicePartnership -eq $true} 
 
 
$casm | foreach-object{ 
$user = get-user $_.name 
$devices = Get-ActiveSyncDeviceStatistics -Mailbox $_.Identity | Where-Object {$_.LastSuccessSync -le $days} 
 
if($devices -ne $null) 
{ 
$devices | foreach$deviicemod = $_.DeviceModel 
$usrname = $user.name 
 
Write-host  "processing....$usrname....Device....$deviicemod" -foreground green 
 
Add-content $output "processing....$usrname....Device....$deviicemod" 
 
Remove-ActiveSyncDevice ([string]$_.Guid) -confirm:$false 
} 
} 
} 
 
#Stop-Transcript 
#############################################################################################

 

Regards

Sukhija Vikas

http://msexchange.me

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s