For this I take advantage of the built in metrics functionality that is part of Hyper-V.
Looking at this report – I realize I should probably filter our replicated virtual machines (those are all the entries with zero data). I guess I will have to fix that at some point in the future. Regardless – here is the code that I use today:
Notes about this code:
- $metricsData contains the output of “get-vm | measure-vm” (this is mentioned in my first post in this series). The reason why I do this is because measure-vm is a heavy command (it uses a chunk of CPU and disk) so I only want to run it once.
- Once again – I use raw HTML to set the color of the table headers.
- Again – I run the output of these commands through Select-Object with the use of the “Expression” option to set column labels appropriately.
- Again – I use ConvertTo-HTML –Fragment to get a nice HTML table outputted.
- At the end of this code I reset the counters, and enable metering on all virtual machines. I do this so that if I add any new virtual machines, they get picked up automatically.