Every administrator who has worked with Windows Server 2008 and later OSes knows the value of PowerShell scripting....
Microsoft is making sure PowerShell becomes the primary scripting language to interact with Windows Server roles, features, Office 365 and Azure clouds. However, not many Hyper-V administrators know that PowerShell can be used to create procedures to perform a complete Hyper-V health check on hosts and the VMs running on them.
When checking Hyper-V host and VM health, you want to look at least a few basic items, listed below:
- General health status of Hyper-V hosts
- General health status of VMs
- Installed roles and features on Hyper-V hosts
Let's take a look at each of the health check items and the necessary PowerShell scripts or commands that you would want to use to get the required data.
General health status of Hyper-V hosts
When it comes to performing a general Hyper-V health check of the hosts, it's important that you check the Hyper-V OS, the Hyper-V OS service pack, memory usages, CPU usages, Hyper-V uptime, total memory, used memory and available memory. There are many PowerShell cmdlets that will provide you with the necessary information, but be sure that the commands you put together are able to collect information from all of your Hyper-V hosts. For stand-alone Hyper-V hosts, you can execute individual PowerShell cmdlets, but to collect information from a Hyper-V cluster, the Get-ClusterNode PowerShell cmdlet is required. Here is an example:
Once you've finished executing the PowerShell script shown above, it will generate a report (Figure A).
General health status of VMs
When performing a Hyper-V health check of VMs running on the hosts, make sure to check the state of the VM, the integration services version, VM uptime, if the VM is clustered or not, virtual processors and memory configured on the VMs as well as VM dynamic memory status. Most of the VM information can be collected using the Get-VM PowerShell cmdlet. The PowerShell script shown below uses this command to collect health check information from VMs configured in a Hyper-V cluster.
This script will generate a CSV report under C:\Temp folder. The report will include VM name, VM current state, VM uptime, VM integration services version and VM overall status (Figure B).
Installed roles and features on Hyper-V hosts
It's important that Hyper-V hosts run only the required roles, in order to avoid memory and CPU consumption by other roles and features. The required roles for a Hyper-V host are the Hyper-V Server role and Failover Clustering feature. To get installed roles and features on Hyper-V hosts, run the Get-WindowsFeature PowerShell command as shown below:
The PowerShell scripts featured in this article can be used for a Hyper-V cluster. While there are other health check tasks you might want to perform based on your requirements, such as checking Hyper-V Replica, the basic things to include in a Hyper-V health check procedure have been highlighted above.
Learn about improvements to Windows Server 2016 Hyper-V Manager
Upgrade Hyper-V VM configuration version in just two steps
Manage VMs with these Windows Server 2016 Hyper-V features