2

I am trying to script something to sync up IIS servers using MSdeploy.

I tried all the possible ways to run the .exe but sometimes I get this error:

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.

When I execute the same script again after running it the first time it works fine. This is how I ended up calling it:

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

Any ideas how to prevent it from failing the first time?

laitha0
  • 4,148
  • 11
  • 33
  • 49
  • Is it possible something in your script is modifying the PATH env var so that upon a second execution, PowerShell is able to find msdeploy.exe? – Keith Hill Jan 15 '14 at 18:27

3 Answers3

1

Why dont you use the powershell cmdlets provided by Web Deploy instead of using the exe? These cmdlets get installed by default since V3.

Shaikh Owais
  • 394
  • 1
  • 7
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;
  • I have tried it the same way you suggested but I still get the same error on the first run. – laitha0 Jan 15 '14 at 16:58
  • If the exe is a console app, which msdeploy.exe is, I don't see much benefit to using Start-Process except to maybe use -verb runas to launch an elevated console to run the app. And passing parameters is a bit more of pain using -ArgumentList. – Keith Hill Jan 15 '14 at 18:25
  • I find that `-ArgumentList` makes things a lot easier. You don't have to worry about quoting rules quite as much, and it's easier to build your arguments separate from invoking the console executable. –  Jan 15 '14 at 18:37
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
Heath
  • 2,986
  • 18
  • 21