This documentation is archived and is not being maintained.

How to Install Virtual Guest Services Using a Script

Updated: January 22, 2009

Applies To: Virtual Machine Manager 2008, Virtual Machine Manager 2008 R2, Virtual Machine Manager 2008 R2 SP1

Integration Components (Hyper-V) and Virtual Machine Additions (Virtual Server), collectively known as virtual guest services in System Center Virtual Machine Manager (VMM), improve the integration and performance of virtual machines. VMM provides a parameter in the Set-VM cmdlet that installs the appropriate virtualization guest service on the virtual machine, depending upon the virtualization software of the host. The following script locates all the virtual machines that are managed by the VMM server that do not have virtualization guest services installed. Then, the script installs the appropriate service on the virtual machines. To copy the entire script, see InstallVirtualGuestServices.ps1.

Explanation of InstallVirtualGuestServices.ps1

Use the Set-VM VMM cmdlet with the InstallVirtualizationGuestServices parameter to install virtualization guest services on the virtual machines that are managed by the VMM server. To get started, connect to the VMM server.

# Filename:         InstallVirtualGuestServices.ps1
# Description:      Finds all virtual machines managed by Virtual Machine
#                   Manager on which virtual guest services are not 
#                   installed and installs the appropriate service.

# Connect to the Virtual Machine Manager server.

$VMMServer = Get-VMMServer -ComputerName ""

Find all the virtual machines that are managed by the VMM server. Then, look for only those virtual machines that do not have virtual guest services installed. If there are no virtual machines that meet these criteria, the script ends with a message.

# Find all virtual machines without virtual guest services.

$VMs = @(Get-VM)
$VMsWithoutServices = @($VMs | where { $_.HasVMAdditions -eq $False })

if ($VMsWithoutServices.Count -eq "0") { throw "All virtual machines have Virtual Guest Services installed." }

Use the Set-VM cmdlet to install virtualization guest services on each virtual machine in the array. This command runs asynchronously so that all virtual machines can be updated simultaneously.

# Install virtual guest services on all the computers in the array.

foreach ($VM in $VMsWithoutServices)
     Set-VM –VM $vm –InstallVirtualizationGuestServices $TRUE -RunAsynchronously