PowerShell计算脚本执行时间的实现方法

另一个方法是设置两个时间快照和结束时间,计算它们的时差。这将告诉你Get-Hotfix执行了多久,得到的输出数据里将包含脚本执行的时间:


$start = Get-Date
Get-HotFix
$end = Get-Date
Write-Host -ForegroundColor Red ('Total Runtime: ' + ($end - $start).TotalSeconds)

文章出处:http://www.pstips.net/