Retrieving Packets Received Discarded Perfmon Counter From Multiple Servers–Updated February 2015

On the Retrieving Packets Received Discarded Perfmon Counter From Multiple Servers post, Tim commented that he had found the script very useful when troubleshooting discarded packets on Exchange 2013 DAG servers.  Using PowerShell  it is very easy to extend the search to discover which other servers are impacted by the packets received discarded issue. 

Since the initial version of the script echoed all results to the console screen, this was not ideal for analysing 200 servers.  When I wrote the script it was to look at a specific DAG, which is only a handful of servers. 

Trying to get the ServerName, NIC, OS Uptime and Perfmon data exported to a CSV was a challenge.  This is not specific for this issue.  It is a technique that comes in handy when you want to pull in bits of data from multiple sources and then easily write out to a CSV or otherwise manipulate the data.

For example in Exchange Get-Mailbox and Get-MailboxStatistics are two separate cmdlets but we often want to combine aspects of their output for reporting purposes.  To make it more interesting, you may also need to pull in data from Get-ADuser and Get-MailboxFolderStatistics into the same report.

How do we get all of the information from multiple sources into a single place?

If only there was a way to customise PowerShell so that we could have custom objects of our own.  Well there is…


Custom PowerShell Objects

We can indeed create custom PowerShell objects and construct them with whatever we want to add to it.  You could maybe say it is a little Frankenstein **, but the marketing people would much prefer to use the word hybrid.

There is a an example of this in the below PowerShell template script:

PowerShell Template

We create a new template object which can be copied and re-used multiple times.  This is a custom PSObject with the property names we choose. In the example below they are Element1, Element2 and Element3.  The names can be changed to suit your preference. 

$TemplateObject = New-Object PSObject | Select-Object Element1, Element2, Element3

And this template can be copied to make new objects as needed:

# Make a copy of the TemplateObject.  Then work with the copy...

$WorkingObject = $TemplateObject | Select-Object *

# Populate the TemplateObject with the necessary details.
$WorkingObject.ServerName = $Server


The above is just one example or creating custom objects – there are many more


Updated Script For Packets Received Discarded

In version 4, the script now outputs to a CSV file.  Script will add one line to the CSV per selected NIC.  If a server has two NICs that means two lines for that server.  This is to allow filtering based on discarded packets and server name in Excel.  A server may have one good NIC and one bad for example. 

The below in an excerpt showing the use of the custom object. 

Using Custom PowerShell Object To Store Data From Multiple Sources


Is this the technique you typically use, or what other interesting approaches do you have to this? 




** – Though remember that Frankenstein was the creator and not the monster…

Rhoderick Milne [MSFT]

Leave a Reply

Your email address will not be published. Required fields are marked *