Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Removing Old ActiveSync Devices Exchange 2010 Powershell

Posted on 2013-02-01
5
Medium Priority
?
2,271 Views
Last Modified: 2013-02-06
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
0
Comment
Question by:KevinKhanMCITP
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 total points
ID: 38858868
$_.guid var contain following value, which cannot be converted to type "Microsoft.Exchange.Configuration.Tasks.ActiveSyncDeviceIdParameter".

guid 
------
8712635a-1ec2-4860-a654-121167c888d9

Open in new window


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

Author Closing Comment

by:KevinKhanMCITP
ID: 38859415
The script now runs as anticipated! Thank you! For future knowledge/readers why did that work?
0
 

Author Comment

by:KevinKhanMCITP
ID: 38859431
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)
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Know the reasons and solutions to move/import EDB to New Exchange Server. Also, find out how to recover an Exchange .edb file and to restore the file back.
How to deal with a specific error when using the Enable-RemoteMailbox cmdlet to create a mailbox in the cloud-based service, for an existing user in an on-premises Active Directory.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question