2017-02-14 31 views
0

我试图从powershell运行nuint控制台在我的应用程序上运行一些Selenium测试。试图获取Powershell中的最新文件夹名称

在PowerShell中条命令是如下:

$command = 'D:\tools\NUnitTestRunner\nunit3-console.exe "\\myserver\Drops\MyProj\MyApp_20170214.1\App.Selenium.Tests.dll"' 
iex $command 

可正常工作。但是,我想要改变的是双“”。我想运行我的回归测试,当一个版本被删除到一个新的App.Selenium.Test.dll将被删除的文件夹 - 与文件夹MyApp_DATE.DropNumber将改变。

所以我可能会安装路径下的\ MYSERVER \滴眼液\的Myproj \像下面的文件夹:

MyApp_20170214.1 
MyApp_20170214.2 
MyApp_20170214.3 
MyApp_20170214.4 

我要动态地获取最新的文件夹,并把它放到命令,而不是在每个去时间和硬编码。这是我曾尝试:

$logFile = "$PSScriptRoot\NunitLog.txt" 
$dir = "\\myserver\Drops\MyProj\" 

#Go get the latest Folder Name 
$latest = Get-ChildItem $dir Where { $_.PSIsContainer } | Sort CreationTime -Descending | Select -First 1 

#remove old log file 
if(Test-Path $logFile) { Remove-Item $logFile } 

"Starting Selenium Tests" | Out-File $logFile -Append 
$latest.name | Out-File $logFile -Append 

#Start nUnit Console and pass argument which is the latest path to the dll of the tests 
#$command = 'D:\tools\NUnitTestRunner\nunit3-console.exe "$latest.name"' 

但是,它不输出文件夹名,日志文件或命令运行它

回答

1

其中,填充时,您的代码是缺少DIR &之间的管道$最新的。另外,$命令行应该在整个字符串中加双引号,因为当用单引号括起来时,PowerShell把它当作字符串文字。要在生成的命令中包含双引号,我们在它们之前添加一个反引号。我们还将$latest.name$()换行以允许PowerShell进行评估 - 否则我们会以文件夹名称末尾的.name结束。

$logFile = "$PSScriptRoot\NunitLog.txt" 
$dir = "\\myserver\Drops\MyProj\" 

#Go get the latest Folder Name 
$latest = Get-ChildItem $dir | Where { $_.PSIsContainer } | Sort CreationTime -Descending | Select -First 1 

#remove old log file 
if(Test-Path $logFile) { Remove-Item $logFile } 

"Starting Selenium Tests" | Out-File $logFile -Append 
$latest.name | Out-File $logFile -Append 

#Start nUnit Console and pass argument which is the latest path to the dll of the tests 
#$command = "D:\tools\NUnitTestRunner\nunit3-console.exe `"$($latest.name)`"" 
+0

这正是我所需要的 - 欢呼 –

+0

很酷。乐意效劳 :) – TechSpud

相关问题