我正在尝试使用PowerShell脚本来提供网卡名称,mac和当前使用情况。以下是我的半工作概念。我只是不确定如何匹配使用与另一方。
$NetworkCards = [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() Foreach ($Card in $NetworkCards) { if ($Card.NetworkInterfaceType -eq "Ethernet") { $Statistics = $null Write-Host "Name: " $Card.Name Write-Host "Mac: " $Card.GetPhysicalAddress() $Statistics = $Card.GetIPv4Statistics() $Statistics #$BytesTotalPersec = $Statistics.BytesTotalPersec #$CurrentBandwidth = $Statistics.CurrentBandwidth #$Math = (($BytesTotalPersec*8)/$CurrentBandwidth)*100 #$Math = [Math]::Round($Math,2) #Write-Host $Math } }
我知道GetIPvStatistics是错误的。我希望在一个完美的世界中从Win32_PerfFormattedData_Tcpip_NetworkInterface获取数据
答案 0 :(得分:0)
为什么不使用那个WMI类?
PS> $data = Get-WmiObject Win32_PerfFormatteData_Tcpip_NetworkInterface |
Where {$_.Name -match 'Ethernet'}
PS> $data.BytesTotalPersec
28388