# NIC Utilisation

**URL:** <https://forums.powershell.org/t/nic-utilisation/7464>\
**Category:** PowerShell Help\
**Created:** [November 4, 2016, 5:27am UTC](https://forums.powershell.org/t/nic-utilisation/7464 "2016-11-04T05:27:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mark-prior](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@mark-prior](https://forums.powershell.org/u/mark-prior)\
**Post date:** [November 4, 2016, 5:27am UTC](https://forums.powershell.org/t/nic-utilisation/7464/1 "2016-11-04T05:27:32Z")

</div>

Hi Gents, i have the below one liner which kind of gets me the info i need (at least current state measurement)

```
Get-WmiObject -class Win32_PerfFormattedData_Tcpip_NetworkInterface -ComputerName eurxmbs04 | Where-Object {$_.Name -like "*HP*"} | format-table Name,BytesTotalPersec, CurrentBandwidth,PacketsPersec
```

it produces a table like below

Name BytesTotalPersec CurrentBandwidth PacketsPersec

* * *

HP Ethernet 1Gb 4-port 331i Adapter 32888336 1000000000 27643  
HP Ethernet 1Gb 4-port 331i Adapter \_2 13934503 1000000000 12983  
HP Ethernet 1Gb 4-port 331i Adapter \_3 16849901 1000000000 18291  
HP Ethernet 1Gb 4-port 331i Adapter \_4 42856234 1000000000 35214  
HP Network Team \_1 30168422 2000000000 19444

However what i would like to do is measure the % similar to what task manager produces and put this at the end of the table, any pointers would be much appreciated

---

<div class="post-metadata">

**Author:** ![mark-prior](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@mark-prior](https://forums.powershell.org/u/mark-prior)\
**Post date:** [November 4, 2016, 8:50am UTC](https://forums.powershell.org/t/nic-utilisation/7464/2 "2016-11-04T08:50:48Z")

</div>

ended up with the below

```
$colInterfaces = Get-WmiObject -class Win32_PerfFormattedData_Tcpip_NetworkInterface -ComputerName eurxmbs04 | Where-Object {$_.Name -eq "HP Ethernet 1Gb 4-port 331i Adapter" -or $_.Name -eq "HP Ethernet 1Gb 4-port 331i Adapter _4" -or $_.Name -eq "HP Network Team _1"} 

   foreach ($interface in $colInterfaces) {

        $bitsPerSec = $interface.BytesTotalPersec * 8
        $totalBits = $interface.CurrentBandwidth
         if ($totalBits -gt 0) {
         $result = (( $bitsPerSec / $totalBits) * 100)
         $interface2 = $interface | select name -ExpandProperty name 
         $interface3 = $interface | select pscomputername -ExpandProperty pscomputername

         $text = "$interface2 on $interface3
         
         Bandwidth utilized: $result %

         

         " 
         
         if ($result -gt 60) {     
         
##Variables

   
    $smtpServer = "smtp.test.com"
    $From = "NIC-Monitor@test.com"
    $SubjectCPY = "NIC $interface2 on $interface3 is above 60% Threshold"
    $Body = "$text"
    $prior = "mark.prior@test.com"

#Email Content
## -cc $mail will mail user account
Send-Mailmessage -smtpServer $smtpServer -from $from -to $Prior -subject $subjectCPY -priority High -Body $Body -BodyAsHtml}
         
         
         
         }}
```

---

<div class="post-metadata">

**Author:** ![richard-siddaway](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@richard-siddaway](https://forums.powershell.org/u/richard-siddaway)\
**Post date:** [November 4, 2016, 10:06am UTC](https://forums.powershell.org/t/nic-utilisation/7464/3 "2016-11-04T10:06:01Z")

</div>

You can simplify your code quite a bit by utilising the pipeline

You’ll need to add your original where-object filter back in and change the threshold in the last where

```
Get-WmiObject -ClassName Win32_PerfFormattedData_Tcpip_NetworkInterface |
where CurrentBandwidth -gt 0 | 
foreach {
   
   $props = [ordered]@{
     Name = $psitem.Name
     Computer = $psitem.PSComputerName
     PercUtilisation = (($psitem.BytesTotalPersec * 8) / $psitem.CurrentBandWidth) * 100
   }
   
   New-Object -TypeName PSObject -Property $props

 } |
 where PercUtilisation -gt 0.5 |
 foreach {
   $text = @"
   $($_.Name) on $($_.Computer)
         
   Bandwidth utilized: $($_.PercUtilisation) %
   
   
"@

 $smtpServer = 'smtp.test.com'
 $From = 'NIC-Monitor@test.com'
 $SubjectCPY = "NIC $($_.Name) on $($_.Computer) is above 60% Threshold"
 $prior = 'mark.prior@test.com'
 Send-Mailmessage -smtpServer $smtpServer -from $from -to $Prior -subject $subjectCPY -priority High -Body $text -BodyAsHtml

 }
```

---

<div class="post-metadata">

**Author:** ![mark-prior](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@mark-prior](https://forums.powershell.org/u/mark-prior)\
**Post date:** [November 7, 2016, 3:14am UTC](https://forums.powershell.org/t/nic-utilisation/7464/4 "2016-11-07T03:14:45Z")

</div>

Thanks richard

---

<div class="post-metadata">

**Author:** ![mark-prior](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@mark-prior](https://forums.powershell.org/u/mark-prior)\
**Post date:** [November 7, 2016, 4:08am UTC](https://forums.powershell.org/t/nic-utilisation/7464/5 "2016-11-07T04:08:25Z")

</div>

Actually another question, if it detects utilisation on 1 NIC over the threshold how can i get the email to encorp the other results that may or may not be over the threshold ? i.e how would i get the below

"Subject: NIC HP Ethernet 1Gb 4-port 331i Adapter \_4 on EURXMBS04 is above 60% Threshold

HP Ethernet 1Gb 4-port 331i Adapter \_4 on EURXMBS04 Bandwidth utilized: 67.128768 %

HP Ethernet 1Gb 4-port 331i Adapter on EURXMBS04 Bandwidth utilized: 20.965184 %

HP Network Team \_1 on EURXMBS04 Bandwidth utilized: 10.7366888 % "

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:40pm UTC](https://forums.powershell.org/t/nic-utilisation/7464/6 "2024-05-16T20:40:02Z")

</div>

Closed on May 16, 2024, 8:40pm UTC


