您现在的位置是:网站首页> 编程资料编程资料
Powershell检查网站响应并计算执行时间例子_PowerShell_
2023-05-26
358人已围观
简介 Powershell检查网站响应并计算执行时间例子_PowerShell_
有时候你需要知道命令的执行时间,例如,你可以使用Invoke-WebReques查看网站的响应,再使用Measure-Command计算执行的时间。
复制代码 代码如下:
$url = 'http://www.powershell.com'
# track execution time:
$timeTaken = Measure-Command -Expression {
$site = Invoke-WebRequest -Uri $url
}
$milliseconds = $timeTaken.TotalMilliseconds
$milliseconds = [Math]::Round($milliseconds, 1)
"This took $milliseconds ms to execute"
其中返回的时间间隔属性中包涵了一个“TotalMilliseconds”属性;如果有必须要你也可以使用Round()函数将其化整,这个例子中我们将保留小数点后第一位。
相关内容
- PowerShell中改变F1帮助文档命令获取方式为在线文档的方法_PowerShell_
- PowerShell ISE自动化简单示例_PowerShell_
- Powershell ISE的抽象语法树编程示例_PowerShell_
- 揭秘PowerShell 5.0新特性和新功能_PowerShell_
- 简单谈谈PowerShell 4.0中的新命令_PowerShell_
- PowerShell 3.0管理Hyper-V 3.0_PowerShell_
- Windows 8 中的 PowerShell 3.0_PowerShell_
- PowerShell管理Win Server 2008 R2_PowerShell_
- 浅谈PowerShell 捕获错误_PowerShell_
- PowerShell打开或关闭光驱_PowerShell_
