A while back, Eric Siron, one of my fellow Altaro.com bloggers, did an excellent write-up regarding Hyper-V integration services. Said post did a great job explaining the need for integration services, what they are, and how they can help System Admins do their jobs.

As of the Windows Server 2012 R2 release, not much has changed in the realm of Hyper-V Integration Services, but some new functionality has been added, such as the new guest services integration, which allows files to be copied from host to guest via the console connection. No virtual networking in the guest is needed to complete said file transfer. As long as you have an active console session to a defined VM, you can copy a file directly to it from the host system via the GUI.

This is certainly a useful feature, but what happens when you need to copy a file via this methodology, but you don’t have access to a machine with Hyper-V Manager or Failover Cluster Manager? The answer, of course, lies with Powershell!

In this post I will be covering the Powershell cmdlet that provides the file transfer functionality, as well as the cmdlets previously available in Windows Server 2012 (non-R2) that facilitated the management of the various Hyper-V Integration Services features.

PLEASE NOTE: In the below examples I have used the Enter-PSSession cmdlet to Powershell into a Hyper-V host remotely This is in no way a requirement as these commands could easily be executed locally or via RDP on the target system as well. However, I’ve demoed it this way due to the amount of time it would take to run said commands locally on several hosts or guest VMs at once, which is a likely scenario when dealing with Integration Services en-mass across an entire environment. Powershell’s remote session and remote targeting capabilities help cut down the time needed for redundant tasks. Additionally, you’ll see use of the Invoke-Command cmdlet later in this post, which I have utilized for very much the same reason.

Eric will be covering Hyper-V management with Powershell’s remote management features in more depth in an upcoming post for those interested.

Integration Service Management

There are 3 cmdlets provided in the Hyper-V powershell module that gives us what we need to start, stop and review the status of existing Hyper-V Integration Services.

First off, we need to list what exactly those command are. Knowing they are Hyper-V functions, and therefore present in the Hyper-V Powershell module, I would issue:

Which will return the below:

IntegrationServices_Get_Command_Rev2

With that in mind, If I want to return a listing of the current Integration Service status on several VMs that reside on the current host, I would just run:

HyperVIntegration_Powershell_Screen2

As you can see in the example above, I’ve queried two virtual machines for Integration Services status. From this screenshot we can see several items.

  • All Integration Services are enabled on both VMs with the exception of the Guest Service Interface, which is the new Server 2012 R2 service that provides the console based file transfers. We’ll enable this shortly.
  • I can also see, that all services are healthy with the exception of the 3 labeled No Contact. This is usually caused by a windows service being stopped on the target guest machine.

I can run the below command to get a status of the associated Windows services that correspond to the 3 Integrations we suspect to be in a stopped state above:

IntegrationServices_Get_Service_Rev2

We see that, as suspected, the needed services are not in a running state. We can utilize a very similar command to start them:

IntegrationServices_Start_Service_Rev2

Once I’ve started the services again, running the below will verify whether they are running or not:

Followed then by:

IntegrationServices_VMInt_Rev2

To show us that all integrations are now healthy and functioning normally. (Shown above)

In addition, I’ve found that another good use of the Get-VMIntegrationService cmdlet is to use it to report what Integration services are out of date on a particular VM. This can be done via:

This can be especially useful when you need to determine which VMs, out of a vast number of guests, need to have the integrations services package updated.

Going forward if I want to disable one of the integration services I would utilize the Disable-VMIntegrationService cmdlet with the below syntax

HyperVIntegration_Powershell_Screen5

We can see that in the above example that once disabled, the Get-VMIntegrationService cmdlet returns the status of that particular service as false.

To re-enable we use the, yup….  You guessed it, Enable-VMIntegrationService cmdlet!

HyperVIntegration_Powershell_Screen6

And we’re back in business on the Heartbeat service!

[optin-monster-shortcode id=”lwzgfpb294pntqna”]

Copying Files with Copy-VMFile

So, thus far we’ve seen how to view and manage the various Hyper-V integration services, how do we utilize the new Copy-VMFile cmdlet that was introduced in Windows Server 2012 R2?

First off, we need to enable that particular service. As we can see above the Guest Service Interface service is in a disabled state.

HyperVIntegration_Powershell_Screen7

Now that the mentioned service is enabled we can transfer files from host to guest with some relatively easy syntax.

HyperVIntegration_Powershell_Screen8

Then we browse to the destination and verify that the new directory and file exists!

HyperVIntegration_Powershell_Screen9

Summary

As you can see, managing and working with Hyper-V Integration Services via Powershell is no major feat. It’s actually quite simple and intuitive if you have any working knowledge of Powershell. In addition to manual use, these concepts could be incorporated into a script for mass Integration Services maintenance of entire virtual infrastructures, making a seemingly daunting task feel like a walk on easy street.

Thanks for reading!