有没有一种简单的方法来计算PowerShell中命令的执行时间,比如Linux中的'time'命令?
我想出了这个:
$s=Get-Date; .\do_something.ps1 ; $e=Get-Date; ($e - $s).TotalSeconds
Run Code Online (Sandbox Code Playgroud)
但我想要更简单的东西
time .\do_something.ps1
Run Code Online (Sandbox Code Playgroud) 我想在自动化PowerShell脚本中进行多次测量。我使用了Get-Date和TotalSeconds。结果看起来像这样:236.908
如何以分钟和秒为单位获得经过的时间?
$startTime = (Get-Date)
$endTime = (Get-Date)
$ElapsedTime = (($endTime-$startTime).TotalSeconds)
Write-Host "Duration: xx min xx sec"
Run Code Online (Sandbox Code Playgroud)