powershell networkinterface将字节转换为千字节

时间:2016-05-25 07:31:43

标签: windows powershell

我想将单位字节转换为千字节。

波纹管的powershell命令输入:

Get-WmiObject -class Win32_PerfFormattedData_Tcpip_NetworkInterface | 
select BytesReceivedPersec , BytesSentPersec , name | 
Where-Object {$_.name -cnotmatch "isatap"} | 
Where-Object {$_.name -cnotmatch "Teredo"} | 
Where-Object {$_.name -cnotmatch "로컬"} | 
% { '{0,10} {1,20} {2,20}' -f $_.BytesReceivedPersec, $_.BytesSentPersec , $_.name}

输出:

627975  483072  Intel[R] 82575L Gigabit Network Connection

但输出单位是字节 我想将单位字节转换为千字节。

1 个答案:

答案 0 :(得分:1)

/1kb添加到BytesReceived表达式并用括号括起来:

Get-WmiObject -class Win32_PerfFormattedData_Tcpip_NetworkInterface | 
select BytesReceivedPersec , BytesSentPersec , name | 
Where-Object {$_.name -cnotmatch "isatap|Teredo|로컬"} |
% { '{0,10} {1,20} {2,20}' -f ($_.BytesReceivedPersec /1kb), ($_.BytesSentPersec /1kb) , $_.name}

您也可以使用-cnotmatch {"isatap|Teredo|로컬"}来缩短代码

相关问题