我有一个命令,我已经构建并存储在PowerShell中的变量中.如果我执行Write-Host并将其复制并粘贴到标准cmd.exe窗口中,则此命令有效.
如何从脚本中执行此命令?
我已经尝试了几种Invoke-Command或Invoke-Expression的组合而没有运气.
这是我构建变量的方式:
$cmd1 = $arcprg + $arcdir + "\" + $site1 + "-" + $hst + "-" + $yesterday + ".zip " + $logpath1 + "u_ex" + $yesterday + ".log"
Run Code Online (Sandbox Code Playgroud)
这是变量在打印到屏幕时的样子:
7z.exe a -tzip c:\arc_logs\site-host-at-web1-100827.zip c:\inetpub\logs\logfiles\w3svc1\u_ex100827.log
Run Code Online (Sandbox Code Playgroud) 使用Powershell和Psake为可视化工作室解决方案创建包和部署.尝试使用msbuild部署数据库项目 - 使用msdos visual studio命令行正常工作
msbuild /target:Deploy /p:UseSandboxSettings=false /p:TargetConnectionString="aConnectionWithSpacesAndSemiColons" "aDatabaseProjectPathWithSpaces"
Run Code Online (Sandbox Code Playgroud)
从powershell调用时,相同的方法调用会导致错误
& msbuild /target:Deploy /p:UseSandboxSettings=false /p:TargetConnectionString="aConnectionWithSpacesAndSemiColons" "aDatabaseProjectPathWithSpaces"
Run Code Online (Sandbox Code Playgroud)
与空间有关 - 无法弄清楚如何在powershell中复制此调用 - 示例数据库连接字符串数据源=.\ SQL2008;初始目录= DocumentExecution; Integrated Security = True;
我显然不知道自己在做什么.
我终于得到了这个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执行Visual Studio的工具MSTest但没有成功:
$testDLL = "myTest.dll"
$mstestPath = "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\mstest.exe"
$arguments = " /testcontainer:" + $testDLL + " /test:UnitTest1"
Invoke-Expression "$mstestPath $arguments"
Run Code Online (Sandbox Code Playgroud)
我收到此错误:"术语'x86'未被识别为cmdlet,函数的名称,......"任何想法?谢谢.
编辑:
好吧,使用"&"而不是"Invoke-Expression"并为每个参数创建单独的变量来解决问题,它只对我使用一个var中的两个都不起作用:
$testDLL = "myTest.dll"
$mstestPath = "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\mstest.exe"
$argument1 = "/testcontainer:" + $testDLL
$argument2 = "/test:UnitTest1"
& $mstestPath $argument1
Run Code Online (Sandbox Code Playgroud)