Question

I apologize if I butchered the terminology for this, and understand I'm very new to PowerShell. I have read over some of the guides and this concept is clearly not getting through to me.

Concept: I want to remove a mobile device from a user in Exchange 2010

  1. Identify user from input

  2. Create variable from input of the PhoneID

  3. Remove the Phone using phoneID variable

I believe my problem is in how I'm passing this data to the next command. I know the appended "@[Identity " that get's added should be removed and I remember reading something about how when you pass data like this Powershell has no context? Here is my very simple script.


Script

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
. $env:ExchangeInstallPath\bin\RemoteExchange.ps1
Connect-ExchangeServer -auto

$PU = Read-Host "Enter Username"

$did = get-activesyncdevice -mailbox $PU | Select-Object identity

Remove-ActiveSyncDevice -Identity $did

Error

My error is as follows, and I've tried to research what I'm doing wrong but I'm just not getting it :-( , I replaced the actual output for the account with XX.

Remove-ActiveSyncDevice : Cannot bind parameter 'Identity'. Cannot convert value "@{Identity=XX" to type 
"Microsoft.Exchange.Configuration.Tasks.ActiveSyncDeviceIdParameter". Error: "Cannot convert the "@{Identity=XX}" value of type 
"Selected.Microsoft.Exchange.Data.Directory.SystemConfiguration.ActiveSyncDevice" to type "Microsoft.Exchange.Configuration.Tasks.ActiveSyncDeviceIdParameter"."
At line:1 char:35
+ Remove-ActiveSyncDevice -Identity $did
+                                   ~~~~
    + CategoryInfo          : InvalidArgument: (:) [Remove-ActiveSyncDevice], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Exchange.Management.Tasks.RemoveMobileDevice

Any help or advice on this would be amazing!

Was it helpful?

Solution

When you use Select-Object and give it just one property name, you get and object with just one property. But even though it only has one property, you still have to reference that one property by name:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
. $env:ExchangeInstallPath\bin\RemoteExchange.ps1
Connect-ExchangeServer -auto

$PU = Read-Host "Enter Username"

$did = get-activesyncdevice -mailbox $PU | Select-Object identity

Remove-ActiveSyncDevice -Identity $did.identity
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top