Sashkin - Fotolia


Use Hyper-V cmdlets to effectively manage both hosts and VMs

With these PowerShell commands, you can check the Hyper-V replication connection and health status, generate a VM compatibility report and list Integration Services components.

With more than 400 Hyper-V cmdlets available to manage hosts, VMs and replication, it can be overwhelming to navigate them. In this article, we will explain how to test the replication connection between Hyper-V hosts, check replication health status, test VM compatibility and find the VM's integration status.

Testing Hyper-V replication connection

If you want to test the Hyper-V replication connection between the primary and replica servers, you can use the Test-VMReplicationConnection PowerShell cmdlet. Although you should test the connection between the primary and replica Hyper-V servers before enabling Hyper-V replication, you can also include a test as a repeated check to be performed every week to ensure Hyper-V replication is operating normally. To check the replication connection status, execute the Hyper-V cmdlet below:

Test-VMReplicationConnection <Hyper-VReplicaServer.TechTarget.Com> 80 Kerberos

The above command creates a connection from the Hyper-V primary server to the server named Hyper-VReplicaServer.TechTarget.Com over port 80 using the Kerberos authentication protocol. If the connection is established, the command will return: "The connection to the specified replica server with the specified parameters was successful."

Checking Hyper-V replication health status

It's important to ensure that replication is healthy and that the replica server is receiving replicas from the primary VM. In the event of a problem with the primary VM, you can bring the replica VM online. If you would like to see the replication health status of all VMs participating in replication, all you need to do is execute the Measure-VMReplication Hyper-V cmdlet. If you want to export the output to a CSV file, execute the Measure-VMReplication | Export-CSV C:\Temp\ReplicationStatus.CSV command. Note that Measure-VMReplication implements two properties: State and Health. State and Health properties store the replication status data for each VM.

If you have a lot of VMs participating in Hyper-V replication, it makes sense to design a small PowerShell script that can help you collect the replication status from the Health property. For example, you can use the PowerShell script below to list all of the VMs that have issues with Hyper-V replication.

code screenshot

Note that, by executing the above PowerShell script, you are only going to see the VMs that have replication errors. It's quite a handy script that you can include in your Hyper-V health check procedure.

Checking VM compatibility report

From time to time, you might want to test VM compatibility to ensure Hyper-V VMs can be live migrated to other Hyper-V hosts and can be imported successfully if required. Hyper-V offers the Compare-VM PowerShell cmdlet that you can use to compare a VM and a Hyper-V host for compatibility. To generate a compatibility report for a VM, execute the following Hyper-V cmdlet:

It's important to ensure that replication is healthy and that the replica server is receiving replicas from the primary VM.

$CompReport = Compare-VM <SQLVM> -DestinationHost ProdHyper-VHost –DestinationStoragePath D:\Storages –IncludeStorage

The command above stores a VM compatibility report in the Incompatibilities property. To retrieve the VM compatibility report, simply execute the PowerShell command below:


Listing VM Integration Services status

Integration Services plays an important role in improving the overall performance of Hyper-V VMs. There are six components installed as part of Integration Services. If you need to retrieve the status of each Integration Services component from all of your VMs, use the Get-VMIntegrationService Hyper-V cmdlet as shown in the command below:

Get-VMIntegrationService –VMName <List of VMs separated by comma>

When you run the command above, it will show the status of each Integration Services component for each VM in a table.

Listing outdated Integration Services on a VM

While the previous command helps you retrieve the status of Integration Services components from VMs, the following Hyper-V cmdlet can help you see if any Integration Services components are out of date on a particular VM.

Get-VMIntegrationService –VMName <List of VMs separated by a comma> | Where-Object {$_SecondaryOperationalStatus –eq “ProtocolMismatch”}

Next Steps

Navigate the many uses of Get-VM

Change Hyper-V VM configuration version

Learn about different Hyper-V checkpoints

Dig Deeper on Microsoft Hyper-V management