Converting time 121.419419 to readable minutes/seconds
PS> $ts = New-TimeSpan -Seconds 1234567PS> '{0:00}:{1:00}:{2:00}' -f $ts.Hours,$ts.Minutes,$ts.Seconds06:56:07
or
PS> "$ts" -replace '^\d+?\.'06:56:07
All you have to do is use the Measure-Command
cmdlet to get the time:
PS > measure-command { sleep 5}Days : 0Hours : 0Minutes : 0Seconds : 5Milliseconds : 13Ticks : 50137481TotalDays : 5.80294918981481E-05TotalHours : 0.00139270780555556TotalMinutes : 0.0835624683333333TotalSeconds : 5.0137481TotalMilliseconds : 5013.7481
The above output itself might be good enough for you, or you can format it appropriately as the the output of Measure-Command is a TimeSpan object. Or you can use ToString
:
PS > (measure-command { sleep 125}).tostring()00:02:05.0017446