Video Screencast Help

Inventorying output from netsh tcp show chimney stats

Created: 13 Jun 2013 • Updated: 13 Jun 2013
Language Translations
jason.f's picture
+2 2 Votes
Login to vote

I recently found a post for someone requesting how to inventory the output from running "netsh int tcp show chimneystats" (original post is here: Since I've been working on learning powershell this would be a good learning opportunity. It actually turned out to be a bit less code then I thought, for the purpose of this article I'll leave out discussing the inventory steps but I will attach the full script to this post.

The first thing we do is assign the output from the command to a variable. I'm piping it to do some filtering on the output since i'm only interested in the lines that start with a number. Normally the output looks like this:

Idx  Supp  Atmpt    TMax    PMax     Olc              Failure Reason
---  ----  -----    ----    ----     ---              --------------
 11    No  -n/a-       0       0       0                       -n/a-
 12    No  -n/a-       0       0       0                       -n/a-
 13    No  -n/a-       0       0       0                       -n/a-

It starts with one blank line and then the column headings, divider and then the interfaces listed by interface index. So my filter goes like this, find only lines where characters positioned at 2-3 (there's one space before the numbers) and match them to a regular expression for numbers. That gives my variable only the lines that are for an interface. Once I have that then I can split up the columns using a regular expressing to match white spaces. Once they're split up into columns I can reference each column by using the number in square brackets after the variable name. I create my own object and assign the properties for the object to the variable.

Since only the interface index is listed on the output I wanted to get the actual name and description so I query WMI, filtering on the interface index which is in my first column. The whole thing is wrapped inside a function so I can call it and assign it to a variable and then run it through a foreach loop and assign the columns to my custom data class by referencing the properties like $chimney.index; $chimney.IntName; etc..

Function Get-ChimneyStats
$Chimneystats = netsh int tcp show chimneystats | where {$_.substring(1,2) -match "\d+"} #Parsing output and grabbing only lines that begin with a number
#Split columns up
$Chimneystats | foreach {$parts = $_ -split "\s+",8
New-Object -Type PSObject -Property @{
    Index = $parts[1]
    IntName = $(Get-WmiObject Win32_networkadapter -Filter "Index= $($parts[1])").name #Query WMI to match Interface ID to name.
    Description = $(Get-WmiObject Win32_networkadapter -Filter "Index= $($parts[1])").description #Query WMI to get interface description
    Supp = $parts[2]
    Atmpt = $parts[3]
    TMax = $parts[4]
    PMax = $parts[5]
    Olc = $parts[6]
    FailReason = $parts[7]

$Chimney = get-chimneystats