Offline Updating Hyper-V VMs


Have a lot of VMs which are offline and want to check if their Integration Tools are up 2 date?
I wrote a little script which does just that.
And as a bonus, when the VM has 2008R2 or higher installed, the Integration Tools are automatically updated with the latest version available on the Hyper-V host you run this on!

HTH

$integrationServicesCabPath="C:\Windows\vmguest\support\amd64\Windows6.2-HyperVIntegrationServices-x64.cab"
$VM = get-vm |?{$_.state -eq "off"}
$latestversion2008up = "6.2.9200.16433"
$latestversion2003 = "6.2.9200.16384"

foreach ($v in $vm){
$vhd = ($v | Get-VMHardDiskDrive -ControllerType IDE).path

$diskNo=(Mount-VHD -Path $vhd –Passthru).DiskNumber
$driveLetter=(Get-Disk $diskNo | Get-Partition).DriveLetter
if ((Get-Disk $diskNo).OperationalStatus -ne 'Online')
{
Set-Disk $diskNo -IsOffline:$false -IsReadOnly:$false
}
[string]$name = $vm.name
$serverprops = New-Object System.Collections.Specialized.OrderedDictionary
$serverprops.add('VMName',$name)

$osversion = switch -wildcard ((get-item ($driveLetter + ":\windows\system32\ntdll.dll")).VersionInfo.ProductVersion)
{
"5.2*" {"Windows Server 2003"}
"6.0*" {"Windows Server 2008"}
"6.1*" {"Windows Server 2008R2"}
"6.2*" {"Windows Server 2012"}
}
$serverprops.add('OSVersion',$osversion)

if ($osversion -eq "Windows Server 2003")
{
$serverprops.add('Update',"NA")
if ((get-item ($driveletter + ":\windows\system32\drivers\vmbus.sys")).VersionInfo.ProductVersion -eq $latestversion2003)
{
$serverprops.add('IntegrationTools',"Up2Date")
}
else
{
$serverprops.add('IntegrationTools',"Outdated")
}

}
elseif ($osversion -eq "Windows Server 2008")
{
$serverprops.add('Update',"NA")
if ((get-item ($driveletter + ":\windows\system32\drivers\vmbus.sys")).VersionInfo.ProductVersion -eq $latestversion2008up)
{
$serverprops.add('IntegrationTools',"Up2Date")
}
else
{
$serverprops.add('IntegrationTools',"Outdated")
}

}
else
{
if ((get-item ($driveletter + ":\windows\system32\drivers\vmbus.sys")).VersionInfo.ProductVersion -eq $latestversion2008up)
{
$serverprops.add('IntegrationTools',"Up2Date")
}

else
{
Add-WindowsPackage -PackagePath $integrationServicesCabPath -Path ($driveLetter + ":\") -ea silentlycontinue -ev 'noupdate'
if ($noupdate)
{
$serverprops.add('Update',"Failed")
}
else
{
$serverprops.add('Update',"Success")
}
}
}
Dismount-VHD -Path $vhd
New-Object -TypeName psobject -Property $serverprops
}

Advertisements

One thought on “Offline Updating Hyper-V VMs

  1. […] apply updated integrational components on virtual disks in the System Center VMM library and found Ben´s script which I altered to fit my goal. This is quite convenient based on that you can schedule it and […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: