I cannot work out how to pass arguments that contain folders with spaces using msdeploy.exe and PowerShell v4.
Sample Powershell Script
write-warning "WITHOUT SPACE"
$fl1 = "d:\nospace\a.txt"
$fl2 = "d:\nospace\b.txt"
$arg1 = "-source:filePath=`"$fl1`""
$arg2 = "-dest:filePath=`"$fl2`""
msdeploy.exe "-verb:sync",$arg1,$arg2
write-warning "WITH SPACE"
$fl1 = "d:\space space\a.txt"
$fl2 = "d:\space space\b.txt"
$arg1 = "-source:filePath=`"$fl1`""
$arg2 = "-dest:filePath=`"$fl2`""
msdeploy.exe "-verb:sync",$arg1,$arg2
When the folder name has no spaces, it works fine, however when it has a space it fails:
msdeploy.exe : Error: Unrecognized argument '"-source:filePath="d:\space'. All arguments must begin with "-".
At E:\PAWS\Payroll System\PES-Branch-FW\Publish\DeployPackage.ps1:253 char:9
+ msdeploy.exe "-verb:sync",$arg1,$arg2
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Error: Unrecogn...begin with "-".:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Error count: 1.
Manually calling msdeploy.exe using the following command:
msdeploy -verb:sync -source:filePath="d:\space space\a.txt" -dest:filePath="d:\space space\b.txt"
This works fine from Command Prompt but does not work from PowerShell.
I have used this blog as an aid but without any luck: http://trycatchfail.com/blog/post/The-trials-and-tribulations-of-using-MSDeploy-with-PowerShell.aspx
Update
I have looked into some more examples. If you perform a standard copy operation powershell is able to pass the path to cmd.exe (copy).
write-warning "WITHOUT SPACE"
$fl1 = "d:\nospace\a.txt"
$fl2 = "d:\nospace\b.txt"
$args = ('"{0}" "{1}"' -f $fl1, $fl2)
write-host $args
cmd /c copy $args
write-warning "WITH SPACE"
$fl1 = "d:\space space\a.txt"
$fl2 = "d:\space space\b.txt"
$args = ('"{0}" "{1}"' -f $fl1, $fl2)
write-host $args
cmd /c copy $args
Using the same approach to update the msdeploy snippet still fails because of the space.
write-warning "WITHOUT SPACE"
$fl1 = "d:\nospace\a.txt"
$fl2 = "d:\nospace\b.txt"
$arg1 = '-source:filePath="{0}"' -f $fl1
$arg2 = '-dest:filePath="{0}"' -f $fl2
$args = '-verb:sync',$arg1, $arg2
msdeploy.exe $args
write-warning "WITH SPACE"
$fl1 = "d:\space space\a.txt"
$fl2 = "d:\space space\b.txt"
$arg1 = '-source:filePath="{0}"' -f $fl1
$arg2 = '-dest:filePath="{0}"' -f $fl2
$args = '-verb:sync',$arg1, $arg2
msdeploy.exe $args
One Solution
https://stackoverflow.com/a/12813048/1497635
I would like to add that three escape characters is absolutely crazy. There must be a neater solution to the problem.