Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables 使用msdeploy在powershell的变量中使用空格_Variables_Powershell_Escaping_Whitespace_Msdeploy - Fatal编程技术网

Variables 使用msdeploy在powershell的变量中使用空格

Variables 使用msdeploy在powershell的变量中使用空格,variables,powershell,escaping,whitespace,msdeploy,Variables,Powershell,Escaping,Whitespace,Msdeploy,使用powershell和msdeploy时,变量中的空格有问题。 这就是我需要的: $IdConnectionString = "Hello World" $msdeploy = "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" cd 'C:\Windows\DtlDownloads\WebServices\WebServices\IdService\_PublishedWebsites\IdService_Packag

使用powershell和msdeploy时,变量中的空格有问题。 这就是我需要的:

$IdConnectionString = "Hello World"
$msdeploy = "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" 

cd 'C:\Windows\DtlDownloads\WebServices\WebServices\IdService\_PublishedWebsites\IdService_Package'

[System.Collections.ArrayList]$msdeployArgs = [string[]]@(
  "-verb:sync",
  "-source:package='IdService.zip'",
  "-verbose",
  "-dest:auto"
  "-setParam:Environment=$IdConnectionString"
  )

& $msdeploy $msdeployArgs
这是错误消息:

msdeploy.exe : Error: Unrecognized argument '"-setParam:Environment=Werk niet"'. All arguments must begin with "-".
At C:\Windows\DtlDownloads\WebServices\WebServices\IdService\_PublishedWebsites\IdService\Deployment\IdServiceWSDeploy.ps1:23 
char:1
+ & $msdeploy $msdeployArgs
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Error: Unrecogn...begin with "-".:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

Error count: 1.
这也适用于:

$msdeploy = "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" 

cd 'C:\Windows\DtlDownloads\WebServices\WebServices\IdService\_PublishedWebsites\IdService_Package'

[System.Collections.ArrayList]$msdeployArgs = [string[]]@(
  "-verb:sync",
  "-source:package='IdService.zip'",
  "-verbose",
  "-dest:auto"
  )


& $msdeploy $msdeployArgs -setParam:Environment=`'Werk niet`'
但是我真的需要这个变量来自动部署。正常情况下,
$IdConnectionString
变量是在与发布管理一起使用的另一个配置脚本中定义的。

请尝试以下方法:

$msdeploy = "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" 
$IdConnectionString = "Hello World"

$msdeployArgs = @{
  verb = 'sync'
  source = "package='IdService.zip'"
  verbose = $true
  dest = 'auto'
  setParam = "Environment='$IDConnectionString'"
  }

  Invoke-Expression "& '$msdeploy' $(&{$args}@msdeployArgs)"
编辑:你们中的大多数人的问题似乎都围绕着引用。在查看了msdeploy文档之后,我认为最简单的解决方案是简单地在可扩展的here字符串中构建命令:

$IdConnectionString=“你好,世界” $msdeploy=“C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe”


我不能真正复制您的测试环境,但基本上您只需要从命令提示符中找到工作的命令字符串,然后在here字符串中复制该字符串并调用它。

我认为您可能需要像这样使用启动过程:

$IdConnectionString = "Hello World"
$msdeploy = "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" 

$msdeployArgs = @(
  "-verb:sync",
  "-source:package='IdService.zip'",
  "-verbose",
  "-dest:auto"
  "-setParam:Environment=`"$IdConnectionString`""
)

Start-Process $msdeploy -NoNewWindow -ArgumentList $msdeployArgs

我要试试这个。我将向您发帖这是错误:C:\Program:术语“C:\Program”无法识别为cmdlet、函数、脚本文件或可操作程序的名称。请检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。第1行字符:1+C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe System.Collections.Dic…+~~~~~~~+CategoryInfo:ObjectNotFound:(C:\Program:String)[],CommandNotFoundException+FullyQualifiedErrorId:CommandNotFoundException$msdeployArgs=@{verb='sync'source=“package='Ordina.RvR.IdService.zip'”verbose=$true dest='auto'setParam=“Environment='IDConnectionString'}调用表达式“&$msdeploy”$(&{$args}@msdeployArgs)“但is不起作用:(这里没有理由使用调用表达式。在PowerShell中调用命令很简单,调用表达式会增加额外的复杂性,这会妨碍更简单的解决方案。@Jason Shirk-很公平。如果你发布更简单的解决方案,我将投赞成票并撤回答案。
$IdConnectionString = "Hello World"
$msdeploy = "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" 

$msdeployArgs = @(
  "-verb:sync",
  "-source:package='IdService.zip'",
  "-verbose",
  "-dest:auto"
  "-setParam:Environment=`"$IdConnectionString`""
)

Start-Process $msdeploy -NoNewWindow -ArgumentList $msdeployArgs