2017-02-14 11 views
0

私は、アプリケーションでいくつかのSeleniumテストを実行するためにpowershellからnuintコンソールを実行しようとしています。Powershellで最新のフォルダ名を取得しようとしています

PowerShellのcommmandは以下の通りです:

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

予想通り、この作品。しかし、私が変更したいのはダブル ""です。 MyApp_DATE.DropNumberフォルダが変更されて、新しいApp.Selenium.Test.dllがドロップされるフォルダにリリースがドロップされたときに回帰テストを実行したい。

だから私はパスの下に持っているかもしれ\ 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"' 

はしかし、それはあなたのコードがDIR &場合、取り込むときの間のパイプがありませんでした

答えて

1

をログファイルにフォルダ名を出力するか、コマンドでそれを実行していない:これは私が試したものです$最新。また、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

関連する問題