试图从PS脚本中获取以下输出(如下所示),并创建另一个输出文件,说明每一步完成所需的时间。时间的格式为日:时:分:秒。
Current output:
[Cpu 1] at [Step 1] completed at 120:15:12:15
[Cpu 1] at [Step 2] completed at 120:15:17:18
[Cpu 1] at [Step 3] completed at 120:16:37:13
由于步骤2完成于120:15:17:18,所以总时间将由120:15:17:18 - 120:15:12:15.步骤3完成于120:16:37:13,所以总时间将由120:16:37:13 - 120:15:17:18。
Desired output:
'Step 2 took xx:xx:xx:xx to complete'
'Step 3 took xx:xx:xx:xx to complete'
使用...
# Examples
Measure-Command { Get-ChildItem -Path C:\Windows\*.txt -Recurse }
Measure-Command {Get-ChildItem C:\Windows -Filter "*.txt" -Recurse}
10, 20, 50 | Measure-Command -Expression { for ($i=0; $i -lt $_ i++) {$i} }
10, 20, 50 | Measure-Command -Expression {for ($i=0; $i -lt $_; $i++) {$i}; "$($_)" | Out-Default }
... 并使用TotalMilliseconds属性作为结果。
或者在你的代码块中使用秒表来获得经过的时间。
# Instantiate and start a new stopwatch
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()