我有一个powershell脚本,它包装了打开十个新的powershell窗口,并且在每个窗口中都使用动态参数调用了powershell脚本MyScript.ps1。我的C:\temp\SystemWrapper.ps1目前是这样的:
$system = "1"
$version = "1.0.0.0"
Write-Host("Triggering system $system / 10 with version $version")
start powershell { Write-Host('Starting system $system / 10 with version $version'); C:\temp\MyScript.ps1 $system $version; Read-Host}系统包装窗口输出:
Triggering system 1 / 10 with version 1.0.0.0第二个powershell窗口输出:
Starting system $system/10 with version $version
C:\temp\myScript.ps1 : Cannot validate argument on parameter 'system'. The argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
At line:1 char:86
+ ... stem/10 with version $version'); C:\temp\myScript.ps1 $system $versio ...
+ ~~~~~~~
+ CategoryInfo : InvalidData: (:) [myScript.ps1], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,myScript.ps1在启动第二个powershell窗口时,SystemWrapper.ps1中变量的值不能正确解析,似乎是作为原始字符串$system和$version传递的。
第二个powershell窗口应如下所示:
Starting system 1 / 10 with version 1.0.0.0
#... and the rest of the script with the arguments $system and $version properly resolved as input parameter如何在第二个powershell窗口中获得预期的输出?
发布于 2021-05-05 22:45:53
使用如下所示的param()块开始您的MyScript脚本:
param (
$System,
$Version
)然后使用以下命令启动它:
Start-Process powershell.exe -ArgumentList "-NoLogo -NoExit -File `"C:\temp\MyScript.ps1`" -System $system -Version $version"https://stackoverflow.com/questions/67396236
复制相似问题