我显然不知道自己在做什么.
我终于得到了这个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 …Run Code Online (Sandbox Code Playgroud) 有人可以向我解释这个结果吗?多年来我试图掌握PowerShell调用命令的语法浪费了很多时间,但是这......我甚至无法猜测如何从输入中获得这个结果.
PS C:\Users\P> & echoargs " ""1"" 2 3 ""4 5 6"" 7 8 9"
Arg 0 is < 1 2 3 4>
Arg 1 is <5>
Arg 2 is <6 7 8 9>
Run Code Online (Sandbox Code Playgroud)
Bueller?
我正在尝试将属性传递给MSBuild.该属性是以分号分隔的值列表.与此问题不同,我正在从PowerShell运行MSBuild.
我明白了:
PS> msbuild .\Foo.sln /p:PackageSources="\\server\NuGet;E:\NuGet"
MSBUILD : error MSB1006: Property is not valid.
Switch: E:\NuGet
Run Code Online (Sandbox Code Playgroud)
如果我从命令提示符运行相同的命令,它工作正常.如何让它在PowerShell中工作?
我在这里尝试一些非常简单的东西,但无法弄清楚我哪里出错了.我已经找到了许多其他有用的讨论 - 特别是在这里 - 但没有发现任何涵盖我的具体情况.
在powershell中,我输入了以下内容:
$path = "c:\program files\"
$path2 = "c:\program files\fred2\"
echoargs $path $path2
echoargs "$path" "$path2"
Run Code Online (Sandbox Code Playgroud)
在两次调用echoargs中,我得到了
Arg 0 is <c:\program files" c:\program>
Arg 1 is <files\fred2">
Run Code Online (Sandbox Code Playgroud)
回来了.如何才能正确传递参数?
注意:在我的真实脚本中,路径变量是由一些配置参数构建的,所以我不能直接用单引号传递它们.
我想在PowerShell上执行cmd,此命令使用分号.然后PowerShell将其解释为多个命令.如何使PowerShell忽略分号并执行我的命令如何使用唯一命令?
例:
Invoke-Expression "msbuild /t:Build;PipelinePreDeployCopyAllFilesToOneFolder /p:Configuration=Debug;_PackageTempDir=$TargetFolder $WebProject"
Run Code Online (Sandbox Code Playgroud)
另一个例子:
Invoke-Expression "test`;test2"
Run Code Online (Sandbox Code Playgroud)
第二个例子回应:
The term 'test' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:6
+ teste <<<< ;teste2
+ CategoryInfo : ObjectNotFound: (teste:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
The term 'test2' is not recognized as the name of a cmdlet, …Run Code Online (Sandbox Code Playgroud) 看来我可以使用单引号或双引号来转义命令行参数:
PS C:\> echo Hello World
Hello
World
PS C:\> echo 'Hello World'
Hello World
PS C:\> echo "Hello World"
Hello World
Run Code Online (Sandbox Code Playgroud)
但是仍然有一些我无法弄清楚的东西,当你希望从包含空格的目录中运行可执行文件时:
PS C:\> c:\program files\test.exe
The term 'c:\program' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again.
At line:1 char:11
+ c:\program <<<< files\test.exe
PS C:\> 'c:\program files\test.exe'
c:\program files\test.exe
PS C:\> "c:\program files\test.exe"
c:\program files\test.exe
PS C:\>
Run Code Online (Sandbox Code Playgroud)
如何让PowerShell运行上面的可执行文件?
我已经阅读了这个答案stackoverflow的答案,它让我在那里中途.这是我需要做的.
执行以下命令:
"c:\myexe.exe <c:\Users\Me\myanswerfile.txt"
Run Code Online (Sandbox Code Playgroud)
如果我从我的powershell脚本中直接运行它
&'c:\myexe.exe <c:\Users\Me\myanswerfile.txt'
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
The term 'C:\myexe.exe <c:\Users\Me\myanswerfile.txt' is not recognized as the name of
a cmdlet, function, script file, or operable program. Check the spelling of the name,or
if a path was included, verif that the path is correct and try again.
Run Code Online (Sandbox Code Playgroud)
现在我尝试了几种变体,包括将原始命令放在一个名为$ cmd的变量中,然后传递
如果我将'<'附加到$ cmd变量,则命令失败并出现与第一个类似的错误.
我很难过.有什么建议?
我试图通过一个简单的变量传递,
没有参数
msbuild MySolution.sln /p:Configuration=Debug /p:Platform="Any CPU"
Run Code Online (Sandbox Code Playgroud)
试试1
$buildOptions = '/p:Configuration=Debug /p:Platform="Any CPU"'
msbuild MySolution.sln + $buildOptions
Run Code Online (Sandbox Code Playgroud)
- >导致MSB1008
试试2
$command = "msbuild MySolution.sln" + $buildOptions
Invoke-expression $command
Run Code Online (Sandbox Code Playgroud)
- >导致MSB1009
我试过这篇文章的解决方案,但我认为这是一个不同的错误.
这就是我想要执行的:
c:\Program Files (x86)\SEQUEL ViewPoint\viewpoint.exe /Setvar((POSTSTR $POSTSTR)(POSTEND $POSTEND)) /G:C:\viewpointfile.vpt /D:C:($BEGDATE 到 $TODDATE) .xls
这是我尝试过的:
$a = "/Setvar((POSTSTR $POSTSTR)(POSTEND $POSTEND))"
$b = "/G:C:\viewpointfile.vpt"
$c = "/D:C:($BEGDATE 到 $TODDATE).xls"
$Viewpoint = "c:\Program Files (x86)\SEQUEL ViewPoint\viewpoint.exe"
&$观点$a $b $c
当我执行此操作时,我收到一条错误消息:
文件 C:\viewpointfile.vpt "/D:C:($BEGDATE 到 $TODDATE).xls" 未找到!
我不确定它从哪里获得额外的报价。如果我只使用 $a 和 $b 运行命令,它运行得很好。
任何帮助将不胜感激。谢谢!:)
更新
manojlds 建议使用echoargs,所以这里是它的输出:
&./echoargs.exe $viewpoint $a $b $c
Arg 0 是 C:\Program Files (x86)\SEQUEL ViewPoint\viewpoint.exe
参数 1 是 /Setvar((POSTSTR 20101123)(POSTEND 20111123))
参数 2 是 /G:C:\viewpointfile.vpt
Arg 3 为 /D:C:(2010-11-23 …
我正在尝试我的第一个 powershell 脚本,但在运行以下代码时出现错误参数错误。如何将参数传递给 powersehll 中的命令?
& "bcdedit" /store c:\boot\bcd /set {bootmgr} device partition=C:
Run Code Online (Sandbox Code Playgroud)
编辑: 此操作的工作代码是:
& "bcdedit" /store c:\boot\bcd /set "{bootmgr}" device partition=C:
Run Code Online (Sandbox Code Playgroud)