我想使用一个变量作为命令的参数,但不能完全弄明白。假设MyCommand
将接受两个参数:option1
和option2
,它们接受布尔值。我如何使用$ newVar替代选项1或2?例如:如何使用PowerShell变量作为命令参数?
$newVar = "option1"
MyCommand -$newVar:$true
我一直相处的东西线“位置参数无法找到接受的说法‘-System.String选项1’。
更具体地:
这里,CSV文件是不同的策略的输出。循环遍历文件中的每个属性,并在我的策略asdf中设置该值;因此-$_.name:$_.value
应替代为-AllowBluetooth:true
。
Import-Csv $file | foreach-object {
$_.psobject.properties | where-object {
# for testing I'm limiting this to 'AllowBluetooth' option
if($_.name -eq "AllowBluetooth"){
Set-ActiveSyncMailboxPolicy -Identity "asdf" -$_.name:$_.value
}}
}
您的意思是'newVar',但是错误地放在'myVar'中? – manojlds 2011-05-10 21:49:07
这是正确的,谢谢。 – Gary 2011-05-10 21:56:15