手机
当前位置:查字典教程网 >脚本专栏 >PowerShell >Powershell检查网站响应并计算执行时间例子
Powershell检查网站响应并计算执行时间例子
摘要:有时候你需要知道命令的执行时间,例如,你可以使用Invoke-WebReques查看网站的响应,再使用Measure-Command计算执行...

有时候你需要知道命令的执行时间,例如,你可以使用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检查网站响应并计算执行时间例子】相关文章:

Windows Powershell 通过函数扩展别名

Windows Powershell创建对象

Powershell中使用WMI工具例子

Windows Powershell 执行文件和脚本

PowerShell小技巧之执行SOAP请求

Powershell中创建自定义对象例子

Powershell打印文本文档例子

PowerShell中使用Get-Date获取日期时间并格式化输出的例子

Powershell截取字符串并添加省略号的例子

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

精品推荐
分类导航