使用 msdeploy 在 powershell 中使用变量中的空格
using white spaces in variable with powershell using 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_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
变量在与 Release Management 一起使用的另一个配置脚本中定义。
这样试试:
$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 文档之后,我认为最简单的解决方案是在此处的可扩展字符串中简单地构建命令:
$IdConnectionString = "Hello World"
$msdeploy = "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe"
$cmd = @"
& '$msdeploy' -verb:Sync -Source:package='IDService.zip' -verbose -dest:auto -setParam:Environment='$IdConnectionString'
"@
invoke-expression $cmd
我真的不能复制你的环境来进行测试,但基本上你只需要找到在命令提示符下运行的命令字符串,然后在此处的字符串中复制它,然后调用它。
我认为您可能需要像这样使用 Start-Process:
$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
我在使用 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
变量在与 Release Management 一起使用的另一个配置脚本中定义。
这样试试:
$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 文档之后,我认为最简单的解决方案是在此处的可扩展字符串中简单地构建命令:
$IdConnectionString = "Hello World" $msdeploy = "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe"
$cmd = @"
& '$msdeploy' -verb:Sync -Source:package='IDService.zip' -verbose -dest:auto -setParam:Environment='$IdConnectionString'
"@
invoke-expression $cmd
我真的不能复制你的环境来进行测试,但基本上你只需要找到在命令提示符下运行的命令字符串,然后在此处的字符串中复制它,然后调用它。
我认为您可能需要像这样使用 Start-Process:
$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