我有一个命令,我已经构建并存储在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;
我正在尝试运行MSTest.exe C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE
.更重要的是,我将当前目录中的所有程序集都设置为单独的/ testcontainer参数.如果没有PowerShell的抱怨,我无法弄清楚如何做到这一点.
$CurrentDirectory = [IO.Directory]::GetCurrentDirectory()
$MSTestCall = '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe"'
foreach($file in Get-ChildItem $CurrentDirectory)
{
if($file.name -match "\S+test\S?.dll$" )
{
$MSTestArguments += "/TestContainer:" + $file + " "
}
}
$MSTestArguments += " /resultsFile:out.trx"
$MSTestArguments += " /testsettings:C:\someDirectory\local64.testsettings"
Invoke-Expression "$MSTestCall $MSTestArguments"
Run Code Online (Sandbox Code Playgroud)
我从这段代码得到的错误是:
Invoke-Expression:您必须在'/'运算符的右侧提供值表达式.
当我尝试在名称中没有空格的目录中调用mstest.exe时,我不会收到此错误(不需要额外的").
当我尝试使用时&
,
&$MSTestCall $MSTestArguments
Run Code Online (Sandbox Code Playgroud)
它将$ MSTestArguments作为单个参数交给MSTest提示抛出.建议?