Search code examples
variablespowershellescapingwhitespacemsdeploy

using white spaces in variable with powershell using msdeploy


I have a problem with white spaces in variable using powershell and msdeploy. This is what I need:

$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

This is the error message:

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.

This also works:

$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`'

But I really need the variable for automatic deployment. Normal the $IdConnectionString variable is defined in another configuration script used with Release Management.


Solution

  • I think you may need to use Start-Process like this:

    $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