Chinh Do

Running MSDEPLOY from PowerShell

12th March 2014

Running MSDEPLOY from PowerShell

I had to spend quite a bit of time figuring this out. So hopefully this will help someone out there. To launch MSDEPLOY from PowerShell, make sure you escape any quote or comma characters.

The “2>&1” at the end allows Powershell to detect errors and bail out if you have $ErrorActionPreference = “Stop”

If you still have problems, download and use EchoArgs.exe to see exactly what PowerShell sees.

Example

 

function Get-MSWebDeployInstallPath(){
  $path = (get-childitem "HKLM:\SOFTWARE\Microsoft\IIS Extensions\MSDeploy" | Select -last 1).GetValue("InstallPath")
  $path = "${path}msdeploy.exe"

  if (!(Test-Path "$path")) {
    throw "MSDEPLOY.EXE is not installed. See http://go.microsoft.com/?linkid=9278654"
  }

  return $path
}

$msdeploy = Get-MSWebDeployInstallPath

& $msDeploy -verb:sync -source:recycleApp `
  -dest:recycleApp=`"${webSiteName}`"`,recycleMode=StopAppPool`,wmsvc=${server}`,userName="${userName}"`,password="${password}" `
  -allowuntrusted -debug 2>&1

This entry was posted on Wednesday, March 12th, 2014 at 2:39 pm and is filed under Dotnet/.NET - C#, PowerShell. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

Leave a Comment

  • Calendar

  • March 2014
    M T W T F S S
    « Jan   Apr »
     12
    3456789
    10111213141516
    17181920212223
    24252627282930
    31