All you have to do is use the Measure-Command cmdlet to get the time:
PS > measure-command { sleep 5} Days : 0 Hours : 0 Minutes : 0 Seconds : 5 Milliseconds : 13 Ticks : 50137481 TotalDays : 5.80294918981481E-05 TotalHours : 0.00139270780555556 TotalMinutes : 0.0835624683333333 TotalSeconds : 5.0137481 TotalMilliseconds : 5013.7481
The above output may be good enough for you, or you can format it accordingly, since the Measure-Command output is a TimeSpan object. Or you can use ToString :
PS > (measure-command { sleep 125}).tostring() 00:02:05.0017446
source share