Powershell 单变量多参数
试图使用几个包含多个参数值的变量Powershell 单变量多参数,powershell,Powershell,试图使用几个包含多个参数值的变量 $iniFileContent["Settings"].GetEnumerator() | Select -ExpandProperty value | ForEach-Object { Convert-WindowsImage -SourcePath $iniFileContent.Locations.ServerISO $_ } 脚本查看my.ini文件: [Settings] CreateVM1=-VHDFormat "VHDX" -Editio
$iniFileContent["Settings"].GetEnumerator() | Select -ExpandProperty value | ForEach-Object {
Convert-WindowsImage -SourcePath $iniFileContent.Locations.ServerISO $_
}
脚本查看my.ini文件:
[Settings]
CreateVM1=-VHDFormat "VHDX" -Edition "ServerStandardEval"
CreateVM2=-VHDFormat "VHDX" -Edition "ServerStandardEval"
[Locations]
ServerISO=C:\server2012.iso
最终结果应该是:
Convert-WindowsImage -SourcePath $iniFileContent.Locations.ServerISO -VHDFormat "VHDX" -Edition "ServerStandardEval"
错误是“找不到接受参数[…]的位置参数”。据我所知,出现问题的原因是变量$\uuu
包含多个参数值,它试图将其用作单个参数
将具有多个参数值的字符串解析为函数的正确方法是什么?使用:
语法
Invoke-Expression [-Command] <String> [<CommonParameters>]
$iniFileContent[“Settings”]显示什么。GetEnumerator()|选择-ExpandProperty值
显示什么?。。。这就是VHDFormat“VHDX”-Edition“ServerStandardEval”的VHDFormat“VHDX”-Edition“ServerStandardEval”的内容。您可以首先向我们展示从ini文件填充$iniFileContent
变量的代码吗?问题已准确更新我所需的内容。非常感谢。
$iniFileContent["Settings"].GetEnumerator() |
Select -ExpandProperty value | ForEach-Object {
iex $("Convert-WindowsImage -SourcePath $($iniFileContent.Locations.ServerISO) " + $_)
}