[英]Powershell: How to pass variable correctly to command
I apologize if I butchered the terminology for this, and understand I'm very new to PowerShell. 如果我为该术语不满意,我深表歉意,并且了解我对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 概念:我想从Exchange 2010中的用户删除移动设备
Identify user from input 从输入中识别用户
Create variable from input of the PhoneID 根据PhoneID的输入创建变量
Remove the Phone using phoneID variable 使用phoneID变量删除Phone
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?
我知道应该删除添加的添加的“ @ [Identity”,并且我记得读过一些有关如何传递数据的信息,例如Powershell没有上下文? 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. 我的错误如下,我试图研究我做错了什么,但我没有明白:-(,我用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! 任何帮助或建议,这将是惊人的!
When you use Select-Object and give it just one property name, you get and object with just one property. 当您使用Select-Object并给它一个属性名称时,您获得和Object都只有一个属性。 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.