这个PowerShell命令行引用/转义是什么?

asg*_*las 12 powershell psake msdeploy

我显然不知道自己在做什么.

我终于得到了这个PowerShell命令.但我无法弄清楚它为什么会起作用.

我担心的是最后的""角色:

    &"C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe" `
    -verb:sync `
    -source:contentPath="$build_directory\deploy" `
    -dest:contentPath="$server_temp_directory,computerName=$server,username=$server_username,password=$server_password" `
    -verbose `
    -postSync=runCommand="powershell -NoLogo -NoProfile -Command $server_temp_directory\remotetasks.ps1 Deploy""
Run Code Online (Sandbox Code Playgroud)

为什么我需要双重双引号?

我的IDE(PowerGUI)说线路没有正确结束,但这是我可以按需要运行命令的唯一方法.

是什么,我 - 和IDE - 不知道在PowerShell中进行qouting?


echoargs的一点输出:

如果我跑:

echoargs -postSync=runCommand="powershell -NoLogo -NoProfile -Command $server_temp_directory\remotetasks.ps1 Deploy""
Run Code Online (Sandbox Code Playgroud)

我明白了:

Arg 0 is <-postSync=runCommand=powershell -NoLogo -NoProfile -Command \remotetasks.ps1 Deploy>
Run Code Online (Sandbox Code Playgroud)

如果我在没有双引号的情况下运行,我得到:

Arg 0 is <-postSync=runCommand=powershell>
Arg 1 is <-NoLogo>
Arg 2 is <-NoProfile>
Arg 3 is <-Command>
Arg 4 is <\remotetasks.ps1>
Arg 5 is <Deploy>
Run Code Online (Sandbox Code Playgroud)

另一件需要注意的是,上面的命令只有在最后一个参数中使用=而不是:时才有效.

这不起作用:

-postSync:runCommand="powershell -NoLogo -NoProfile -Command $server_temp_directory\remotetasks.ps1 Deploy""
Run Code Online (Sandbox Code Playgroud)

编辑

现在我尝试了这样的阵列解决方案:

$arguments = @("-verb:sync",
               "-source:contentPath=$build_directory\deploy",
               "-dest:contentPath=$server_temp_directory,computerName=$server,username=$server_username,password=$server_password",
               "-verbose",
               "-postSyncOnSuccess:runCommand=powershell -Command $server_temp_directory\remotetasks.ps1 Deploy")
&"C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe" $arguments
Run Code Online (Sandbox Code Playgroud)

我仍然得到同样的错误:

错误:无法识别的参数'" - postSyncOnSuccess:runCommand = powershell -Command c:\ temp\kslog\remotetasks.ps1 Deploy"'.所有参数必须以" - "开头.

我在这里做错了吗?

Rom*_*min 11

这是一个臭名昭着的问题.票证"执行需要引号和变量的命令实际上是不可能的"是投票最多的错误:https://connect.microsoft.com/PowerShell/Feedback

你也可以找到一些解决方法.但我建议您将所有参数组合为数组,并使用&运算符调用此数组的本机命令.请参阅答案和示例: 使用PowerShell从包含空格的目录运行EXE文件,执行存储在Powershell变量中的命令

我没有使用msdeploy.exe,也无法为您的案例提供一些演示代码.但是我很好地将这种方法应用于许多其他棘手的本机命令.请尝试一下,让我们知道结果.

PS从技术上讲,这不是你问题的答案,但我认为你仍然在寻找一种切实可行的方法,所以它仍然可能会有所帮助.