本文介绍了当参数有空格时,如何从powershell调用msdeploy?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我在参数中遇到空格问题,我尝试从powershell脚本发送到msdeploy。I'm running into a problem with spaces in my parameters that I try to send into msdeploy from a powershell script.还有很多其他相关文章但他们都没有解决问题。 使用Power Shell和MSDeploy时遇到的问题。 类似的SO问题不起作用:如何使用带空格和引号的参数在powershell中运行exe文件 PowerShell BUG: 执行需要引号和变量的命令实际上是不可能 另一个SO问题不起作用:在PowerShell 2.0中传递参数 There are a number of other related articles but none of them solve the problem.Problems Using Power Shell And MSDeploy.Similar SO issue that doesn't work: How to run exe in powershell with parameters with spaces and quotesPowerShell BUG: Executing commands which require quotes and variables is practically impossibleAnother SO issue that doesn't work:Passing parameters in PowerShell 2.0当我使其变得更复杂时,成功然后失败的最简单的例子就是转储默认的网络坐标e。The simplest example that succeeds and then fails when I make it more complicated is just dumping the default web site. $ msdeploy =C:\Program Files \IIS\Microsoft Web Deploy\msdeploy.exe &$ msdeploy -verb:dump -source:appHostConfig =`'默认网站'' - verbose == SUCCESS $msdeploy = "C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe"&$msdeploy -verb:dump -source:appHostConfig=`'default web site`' -verbose==SUCCESS这一个? $ sitename =默认网站 &$ msdeploy -verb:dump -source:appHostConfig = $ sitename - 详细 ==失败,出现以下错误 msdeploy.exe:错误:无法识别的参数' - source:appHostConfig = default'。所有参数必须以 - 开头。 在C:\ xxxx \ test.ps1:122 char:6 +& + CategoryInfo:NotSpecified :(错误:Unrecogn .. .begin with - :String)[],RemoteException + FullyQualifiedErrorId:NativeCommandError 错误计数:1。 $sitename="default web site"&$msdeploy -verb:dump -source:appHostConfig=$sitename -verbose==FAIL with the following errormsdeploy.exe : Error: Unrecognized argument '"-source:"appHostConfig=default'. All arguments must begin with "-".At C:\xxx\test.ps1:122 char:6+ & + CategoryInfo : NotSpecified: (Error: Unrecogn...begin with "-".:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandErrorError count: 1.以下变化也失败 #FAIL $ sitename =`'默认网站'' $ sitename =`'默认网站`' $ sitename =`''默认网站'' $ sitename =默认网站 $ sitename ='默认网站' The following variations have also failed#FAIL$sitename=`'default web site`'$sitename=`'"default web site"`'$sitename="`'default web site`'"$sitename="default web site" $sitename="'default web site'"&$ msdeploy -verb:dump-source:appHostConfig = $ sitename-verbose &$ msdeploy -verb:dump -source:appHostConfig =$ sitename-verbose &$ msdeploy -verb:dump -source:appHostConfig ='$ sitename'-verbose &$ msdeploy -verb:dump -source:appHostConfig =`'$ sitename`'-verbose &$ msdeploy -verb:dump -source:appHostConfig =`$ sitename` -verbose &$msdeploy -verb:dump "-source:appHostConfig=$sitename" -verbose&$msdeploy -verb:dump -source:appHostConfig="$sitename" -verbose &$msdeploy -verb:dump -source:appHostConfig='$sitename' -verbose &$msdeploy -verb:dump -source:appHostConfig=`'$sitename`' -verbose &$msdeploy -verb:dump -source:appHostConfig=`"$sitename`" -verbose我我不知所措。我工作的每个人都不知所措。说真的很糟糕。我喜欢Powershell。我喜欢msdeploy。我不能说我喜欢把它们放在一起。看起来可能更容易关注API而不是cli。I'm at a loss. Everyone I work with is at a loss. Seriously this sucks. I loved Powershell. I loved msdeploy. I can't say that I love putting them together. It looks like it may have been easier to focus on the API instead of the cli. Emperor XLII建议的字符串数组中的参数运行良好。以下文章介绍了另一种解决方案:使用MSDeploy和PowerShell的试验和磨难 The parameters in the string array suggested by Emperor XLII works well. An alternative solution is presented in the following article: The trials and tribulations of using MSDeploy with PowerShell function PushToTarget([string]$server, [string]$remotePath, [string]$localPath) { cmd.exe /C $("msdeploy.exe -verb:sync -source:contentPath=`"{0}`" -dest:computerName=`"{1}`",contentPath=`"{2}`" -whatif" -f $localPath, $server, $remotePath )} 推荐答案使用 Keith的答案 如何使用带空格和引号的参数在powershell中运行exe 你链接的问题,运行 echoargs -verb:dump -source:appHostConfig = $ sitename -verbose 给了我这个输出:Using the technique from Keith's answer to How to run exe in powershell with parameters with spaces and quotes question you linked to, running echoargs -verb:dump -source:appHostConfig=$sitename -verbose gave me this output:Arg 0 is <-verb:dump>Arg 1 is <-source:appHostConfig=default>Arg 2 is <web>Arg 3 is <site>Arg 4 is <-verbose>这将解释 appHostConfig = default msdeploy 正在看到。运行 echoargs -verb:dump-source :appHostConfig = $ sitename-verbose , $ sitename =默认网站,似乎会产生所需的参数:Running echoargs -verb:dump "-source:appHostConfig=$sitename" -verbose, with $sitename = "default web site", appears to result in the desired arguments:Arg 0 is <-verb:dump>Arg 1 is <-source:appHostConfig=default web site>Arg 2 is <-verbose> 虽然从您的列表中可以看出这对您不起作用。Though from your list, it appears that this did not work for you.您可能尝试的另一种方法是在数组中构建参数列表,powershell可以自动转义。例如,它提供与上面相同的输出:Another method you might try is building up the list of arguments in an array, which powershell can automatically escape. For example, this gives the same output as above:[string[]]$msdeployArgs = @( "-verb:dump", "-source:appHostConfig=$sitename", "-verbose")echoargs $msdeployArgs 这篇关于当参数有空格时,如何从powershell调用msdeploy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-21 03:26