0

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?

1
  • What have you tried for the time? As you've already worked out, get-date accepts .NET formatting strings, and you have the date - adding time is just an extension of that. Commented Dec 3, 2015 at 21:44

2 Answers 2

1

After a quick google search I found this reference:

Get-Date -f yyyy-MM-dd-HH-mm-ss
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.