How do you call msdeploy from powershell when the parameters have spaces?

后端 未结 9 1244
忘了有多久
忘了有多久 2020-11-30 05:52

I\'m running into a problem with spaces in my parameters that I try to send into msdeploy from a powershell script.

There are a number of other related articles but

相关标签:
9条回答
  • 2020-11-30 06:30

    I've used some ideas from answers above and came up with the following simpler function to do the thing.

    Note that it is important to give the full path to MSDeploy as when running under the build agent it sometimes doesnt recognise the PATH to msdeploy.

    function Deploy([string]$server, [string]$remotePath, [string]$localPath) {
            $msdeploy = "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe";
            cmd.exe /C $("`"{3}`" -verb:sync -source:contentPath=`"{0}`" -dest:computerName=`"{1}`",contentPath=`"{2}`" " -f $localPath, $server, $remotePath , $msdeploy )
        }
    

    Usage

    Deploy $hostName $remotePath $source
    
    0 讨论(0)
  • 2020-11-30 06:39

    Just adding another way in case it is helpful to anyone:

    Invoke-Expression "& '[path to msdeploy]\msdeploy.exe' --% -verb:sync -source:contentPath=`'$source`' -dest:contentPath=`'$dest`'"
    

    "--%" is new to powershell 3. From here: "You simply add a the --% sequence (two dashes and a percent sign) anywhere in the command line and PowerShell will not try to parse the remainder of that line."

    0 讨论(0)
  • 2020-11-30 06:40

    Found a working solution and easy fix. Reference: http://answered.site/all-arguments-must-begin-with--at-cwindowsdtldownloadswebserviceswebservicesidservicepublishedwebsitesidservicedeploymentidservicewsdeployps123/4231580/

    $msdeploy = "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe"
    $msdeployArgs = @(
    "-verb:sync",
    "-source:iisApp='Default Web Site/HelloWorld'",
    "-verbose",
    "-dest:archiveDir='c:\temp1'"
    )
    Start-Process $msdeploy -NoNewWindow -ArgumentList $msdeployArgs
    
    0 讨论(0)
提交回复
热议问题