我试图将一个变量用作命令的参数,但无法完全弄清楚。假设MyCommand
将接受两个参数:option1
和option2
,它们接受布尔值。 我该如何使用$newVar替换选项1或2?例如:
$newVar = "option1"
MyCommand -$newVar:$true
我不断收到类似于'无法找到接受参数“-System.String option1”的位置参数'的消息。
更具体地:
这里,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