soa*_*dos 3 powershell parsing powershell-2.0
我想获得计算机在一定时间间隔内发送/接收的总字节数.
Powershell有一个方便的cmdlet,可以让我访问该信息(Qualcomm Atheros AR9285无线网络适配器是我的界面名称):
Get-Counter -Counter "\Network Interface(Qualcomm Atheros AR9285 Wireless Network Adapter)\Bytes received/sec" -Continuous
它获得的数据很好,但它是这样的:

关闭我可以让它以我想要的方式出现,Get-Counter -Counter "\Network Interface(Qualcomm Atheros AR9285 Wireless Network Adapter)\Bytes received/sec" -Continuous | Format-Table -Property Readings但在我想要的值前面仍然有一个很长的路径名.
另外,如果我尝试将输出设置为某个变量,则不会完成任何赋值(变量保持为null).
如何以合适的格式获取此数据?
注意:目标是保持此信息的运行记录,然后在达到阈值时执行某些操作.我能做到这一点,如果我可以让上述工作,但如果有更好的方法,我很乐意使用它.
管道Foreach-Object并从CounterSamples属性获取值.CounterSamples是一个数组,值在第一项中:
Get-Counter -Counter "\Network Interface(Qualcomm Atheros AR9285 Wireless Network Adapter)\Bytes received/sec" -Continuous |
Foreach-Object {$_.CounterSamples[0].CookedValue}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5626 次 |
| 最近记录: |