-ArgumentList中的启动过程变量

Jam*_*mie 1 windows powershell

我想知道是否有更多专业知识的人可以帮助我解决我在使用Variables -ArgumentList时遇到的一个小问题Start-Process.

如果我在不使用的情况下运行Exe Start-Process

.\DeploymentServer.UI.CommandLine.exe register --estNumber $Number --postcode $PostCode --password $Password
Run Code Online (Sandbox Code Playgroud)

一切正常,命令运行,软件注册.

如果我试试

Start-Process .\DeploymentServer.UI.CommandLine.exe -ArgumentList "register --estNumber $Number --postcode $PostCode --password $Password" -Wait -NoNewWindow
Run Code Online (Sandbox Code Playgroud)

要么

$Arguments = "register --estNumber $Number --postcode $PostCode --password $Password"
Start-Process .\DeploymentServer.UI.CommandLine.exe -ArgumentList $Arguments -NoNewWindow -Wait
Run Code Online (Sandbox Code Playgroud)

该命令运行但无法注册,说明它无法与提供的详细信息匹配.所以我假设问题在于传递参数Start-Process,或者-ArgumentList解释字符串中的变量.我错过了一些非常简单的东西吗?可能与$在-ArgumentList?

Ans*_*ers 7

你有一个空格$postcode,所以你需要把参数放在引号中:

Start-Process .\DeploymentServer.UI.CommandLine.exe -ArgumentList "register --estNumber $Number --postcode `"$PostCode`" --password $Password" -Wait -NoNewWindow
Run Code Online (Sandbox Code Playgroud)