2

我正在尝试编写脚本以使用 MSdeploy 同步 IIS 服务器。

我尝试了所有可能的方式来运行 .exe,但有时我会收到此错误:

The term 'C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe' is 
not recognized as the name of a cmdlet, function, script file, or 
operable program. Check the spelling of the name, or if a path was included, 
verify that the path is correct and try again.

当我第一次运行后再次执行相同的脚本时,它工作正常。这就是我最终称呼它的方式:

& 'C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe' -verb:sync ...

任何想法如何防止它第一次失败?

4

3 回答 3

1

为什么不使用 Web Deploy 提供的 powershell cmdlet 而不是使用 exe?这些 cmdlet 从 V3 开始默认安装。

于 2014-01-27T19:35:53.297 回答
0

I generally recommend that people use the Start-Process cmdlet to call external executables.

$MsDeploy = 'C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe';
$ArgumentList = '-verb:sync ... ... ...';
Start-Process -FilePath $MsDeploy -ArgumentList $ArgumentList -Wait -NoNewWindow;
于 2014-01-15T16:42:48.653 回答
0

Keep in mind that C:\Program Files gets redirected for 32-bit processes, so

  1. Make sure you're starting the same process bitness for powershell.exe (or whatever is hosting PowerShell).
  2. Use $env:ProgramFiles for a more robust script and put it in quotes along with the full path since the path will likely have spaces in it.

To always use the 32-bit powershell process, on a 32-bit machine run:

%SystemRoot%\system32\WindowsPowerShell\v1\powershell.exe

On a 64-bit machine, run:

%SystemRoot%\SysWOW64\WindowsPowerShell\v1\powershell.exe
于 2014-01-15T21:45:10.917 回答