Reputation: 6465
I'm pretty new to Powershell and would like to output the result of a command to a file which has a timestamp. Currently I could get the date but I can't get the time. Here is what I have:
mstest /testcontainer:"C:\CodedUITests\CodedUISP.dll" /resultsfile:"C:\CodedUITests\TestResults\result $(get-date -f yyyy-MM-dd)$.trx"
How can I get the time as well?
Upvotes: 0
Views: 96
Reputation: 1616
I'm doing almost the same thing! Here's my code:
$outputFile = "$tempLocation\work\$($solutionName)_$((Get-Date -Format s).ToString().Replace('-','').Replace(':','')).trx"
Write-Verbose "$($MyInvocation.MyCommand.Name): Running MSTest.exe..."
Invoke-ExternalCommand MSTest.exe @(
"/testcontainer:$testContainer",
"/resultsfile:$outputFile")
```
Invoke-ExternalCommand is just an abstracted function that calls the mstest command. Doing this allows me to mock the call making Pester testing easier.
This is what the trc file is named: SolutionName_20151015T113206.trx
Upvotes: 1
Reputation: 1716
After a quick google search I found this reference:
Get-Date -f yyyy-MM-dd-HH-mm-ss
Upvotes: 1