Hyper-V v3, PowerShell, Scripting, Virtualization
Leave a comment

PoshUtils: Set (enable or disable) resource metering on clustered Hyper-V virtual machines

In Windows Server 2012 with Hyper-V role, we can enable VM resource metering to measure the utilization of four resource types (CPU, memory, network, and disk) of Hyper-V virtual machines. Once the resource metering is enabled, using Enable-VMResourceMetering, we can use Measure-VM cmdlet to retrieve the utilization of a VM. Now, there are Enable-VMResourceMetering and Disable-VMResourceMetering cmdlets to enable and disable resource metering on an individual VM (-VMName parameter) or a group of VM objects (-VM parameter).

So, what is this clustered Hyper-V virtual machines I am referring to? Well, the two cmdlets I just mentioned aren’t cluster object aware. This means you cannot give these cmdlets a clustered group object and then enable or disable resource metering on those virtual machine objects. So, this is where the following function will help you. It takes the name of the Hyper-V cluster as an input and enable or disable VM resource metering on all the virtual machines in the given cluster. You may already know that the Get-VM cmdlet is cluster object aware. So, we can use that to retrieve a list of virtual machine objects in the cluster.

Make a note that this script needs to be run on the Hyper-V host that is a part of the cluster. We need access to the Cluster cmdlets. By default, without the -Disable switch, this function will attempt to enable resource metering.

So, here is what we are doing:
1. We are getting the cluster group objects of group type VirtualMachine and then passing it to the Get-VM cmdlet to retrieve the virtual machine objects.

2. Once we have the list of virtual machines in the Hyper-V cluster, we can simply enable or disable resource metering.

 

Filed under: Hyper-V v3, PowerShell, Scripting, Virtualization

by

Ravikanth is a principal engineer and the lead architect for Microsoft and VMware virtualized and hybrid cloud solutions within the Infrastructure Solutions Group at Dell EMC. He is a multi-year recipient of Microsoft Most Valuable Professional (MVP) award in Windows PowerShell (CDM) and Microsoft Azure. Ravikanth is the author of Windows PowerShell Desired State Configuration Revealed (Apress) and leads Bangalore PowerShell and Bangalore IT Pro user groups. He can be seen speaking regularly at local user group events and conferences in India and abroad.