在 Powershell 中使用时间创建文件名

create a file name using time in Powershell

我是 Powershell 的新手,想将命令的结果输出到具有时间戳的文件中。目前我可以得到日期,但我无法得到时间。这是我拥有的:

mstest /testcontainer:"C:\CodedUITests\CodedUISP.dll" /resultsfile:"C:\CodedUITests\TestResults\result $(get-date -f yyyy-MM-dd)$.trx"

我怎样才能得到时间?

经过快速 google 搜索,我发现 this reference:

Get-Date -f yyyy-MM-dd-HH-mm-ss

我也在做几乎同样的事情!这是我的代码:

        $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只是调用mstest命令的抽象函数。这样做可以让我模拟调用,使 Pester 测试更容易。

这就是 trc 文件的名称:SolutionName_20151015T113206.trx