Link to home
Start Free TrialLog in
Avatar of KevinKhanMCITP
KevinKhanMCITPFlag for United States of America

asked on

Removing Old ActiveSync Devices Exchange 2010 Powershell

Any suggestions on what I'm doing wrong with this script?

$Mailboxes = $null
$Devices = $null

$Mailboxes = Get-CASMailbox -Filter {HasActivesyncDevicePartnership -eq $true} -resultsize Unlimited

$Devices = $Mailboxes | %{Get-ActiveSyncDeviceStatistics -Mailbox $_.Identity} | ?{($_.LastSuccessSync -ne $null) -and ($_.LastSuccessSync -le (Get-Date).AddDays(-14))}

$Devices | %{Remove-ActiveSyncDevice -identity $_.guid}

Open in new window



Error Message: "Cannot process argument transformation on parameter 'Identity'. Cannot convert the "8712635a-1ec2-4860-a654-121167c888d9" value of type "System.Guid" to type "Microsoft.Exchange.Configuration.Tasks.ActiveSyncDeviceIdParameter".
    + CategoryInfo          : InvalidData: (:) [Remove-ActiveSyncDevice], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Remove-ActiveSyncDevice"

However, when I use the GUID property tag in an individual "remove-activesyncdevice" cmdlet...it works.

Also, if I use the $_.Identity variable in place of the $_.GUID variable it works for some users but has trouble with others. Saying it cannot find the recipient
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of KevinKhanMCITP

ASKER

The script now runs as anticipated! Thank you! For future knowledge/readers why did that work?
For readers,

This script finds All ActieSync Devices that have not successfully sync'd with the Exchange Server longer than 14 days only excluding the devices that have not reported back to the Exchange Server (leaving the lastsuccesssync field $null)