Get NIC Utilization By Powershell

$counters = @()
foreach ($inst in (new-object System.Diagnostics.PerformanceCounterCategory("network interface")).GetInstanceNames())
{ 
        $cur = New-Object system.Diagnostics.PerformanceCounter('Network Interface','Bytes Total/sec',   $inst)
         $max = New-Object system.Diagnostics.PerformanceCounter('Network Interface','Current Bandwidth', $inst)
         $cur.NextValue() | Out-Null
         $max.NextValue() | Out-Null
         $counters += @{"Throughput"=$cur;"Bandwidth"=$max;"Name"=$inst}
}
sleep 2
foreach($counter in $counters)
{ 
    $curnum = $counter.Throughput.NextValue()
    $maxnum = $counter.Bandwidth.NextValue()
    New-Object PSObject -Property @{"Util"=$((( $curnum * 8 ) / $maxnum ) * 100);"Name"=$counter.Name}
}

 

posted @ 2012-12-03 14:39  asbhl-kXi39aVYu  阅读(158)  评论(0)    收藏  举报