我只是希望能够从一个PS脚本传递一个参数到另一个,目前我的脚本(SCRIPT1)如下(一切都归功于用户CB):传递参数
$filepath = Resolve-Path "script2.ps1"
start-process -FilePath powershell.exe -ArgumentList "-file `"$($filepath.path)`""
这通过另一个PowerShell实例成功打开另一个脚本。现在我希望能够将参数传递给'script2.ps1'脚本。我曾尝试以下但这并不不行:
script1.ps1
$name = read-host "The name"
$filepath = Resolve-Path "script2.ps1"
start-process -FilePath powershell.exe -ArgumentList "-file `"$($filepath.path)`"-name $name"
script2.ps1
Param(
[string]$name
)
write-host $name
这应该简单地传过来$名字从SCRIPT1为$在script2中的名称。我认为我很接近但不够接近!
感谢您的帮助!
再次袭击!非常感谢您的帮助,非常感谢 – user3402227
@ user3402227很高兴提供帮助!根据Duncan的评论......我也很好奇,知道为什么你在这种情况下使用启动过程;) –