PowerShell & MSDeploy - Arguments with Spaces

后端 未结 4 1033
予麋鹿
予麋鹿 2021-01-07 10:39

I cannot work out how to pass arguments that contain folders with spaces using msdeploy.exe and PowerShell v4.

Sample Powershell Script



        
4条回答
  •  借酒劲吻你
    2021-01-07 11:17

    When invoking commands PowerShell does some auto quoting that does not work well with MSDeploy. There are a couple of ways to avoid the auto quoting. One is to use the Start-Process cmdlet where you can specify the exact command line that you want but it can become a bit tedious to get the output of the new process to appear as output of the PowerShell script that you are running.

    Another option is to use the --% specifier to turn off PowerShell parsing. However, doing that will not allow you to use variables in the command line because - well, parsing has been turned off. But you can get around this by using the Invoke-Expression cmdlet to first build the command line including the --% and whatever variables you want and then let PowerShell evaluate it:

    $fl1 = "D:\space space\a.txt";
    $fl2 = "D:\space space\b.txt";
    $arguments = "-verb:sync -source:filePath=""$fl1"" -dest:filePath=""$fl2"""
    $commandLine = 'msdeploy.exe --% ' + $arguments
    Invoke-Expression $commandLine
    

提交回复
热议问题