Building a Network Usage PowerShell Monitor

The Chairman has issued a new PowerShell scripting challenge if you feel you are worthy of accepting it. These challenges are meant to not only prove your worth as a PowerShell Warrior but to also help educate and hone your skills. You are encouraged to post links to your work and solutions in the comments so that others may learn from your wisdom and experience.

The Intermediate Baseline

On Windows platforms, you can obtain a wealth of performance information. For this challenge, the Chairman is interested in network utilization for the primary network interface. Specifically, the number of bytes sent and received per second and the total. As a starting point, your challenge is to build a PowerShell tool that will get this information and display the result showing the 3 specified values, the computer name (in upper case), the interface name, and the timestamp of each sample. You should be able to run the command and see the results in as close to real-time as possible. If you can display results in an easy to read format so much the better.

The user of your tool should be able to specify the monitoring conditions such as total samples and intervals.

Advanced Expectations

For next-level scripters, The Chairman would like a visual representation of the values formatted as Kbps, which may not immediately comes to mind. Instead of building a WPF-based GUI, you should use the Write-Progress cmdlet. The PercentComplete bar can make a nice bar graph. This will be very helpful when you run to run your tool on a continuous basis.

Here’s a sample of what you might create. Although you are not bound to this format.

Bonus Challenges

If you find even the advanced challenge not challenging enough, you are welcome to enhance your tool even further by meeting these criteria.

  • Let the user specify the network interface from a list of available choices.
  • Be able to monitor usage from a remote computer using alternate credentials.
  • Include an option to save the results to a file or variable.
  • Alter the Progress bar color based on a condition such as if the Total exceeds some threshold.
  • Instead of using Write-Progress, create a console-based alternative.
  • If you build a console-based alternative, use ANSI escapes to colorize the output in PowerShell 7.

4 Replies to “Building a Network Usage PowerShell Monitor”

Leave a Reply

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