Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 单变量多参数_Powershell - Fatal编程技术网

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) " + $_)
}