Q: I'm trying to use your script to offline patch a VHD file, but it's not working on Windows 7 or Windows 2008 R2--why?
A. The script I created which is available at Windows IT Pro's "Add Updates to an Offline VHD or WIM File" was written specifically for Windows 8 and Windows Server 2012. It uses the Mount-VHD and Dismount-VHD cmdlets, which aren't available in Windows 7 and Windows Server 2008 R2, so the script would fail.
For a Windows Server 2008 R2 box that has the Hyper-V role installed, an alternate approach for mounting and dismounting the virtual hard disk (VHD) would be to use the Msvm_ImageManagementService. For example, I would replace the line in my original script:
mount-vhd -path $updateTarget
With:
if (Get-WmiObject win32_OperatingSystem -Filter "Version > '6.2'") #if Windows 2012 { mount-vhd -path $updateTarget } else #Windows 2008 R2 have to mount another way { $VHDService = get-wmiobject -class "Msvm_ImageManagementService" -namespace "root\virtualization" -computername "." $VHDService.Mount($updateTarget) }
Likewise you would need to replace the dismount code to be this:
if (Get-WmiObject win32_OperatingSystem -Filter "Version > '6.2'") #if Windows 2012 { dismount-vhd -path $updateTarget -confirm:$false } else { $VHDService = get-wmiobject -class "Msvm_ImageManagementService" -namespace "root\virtualization" -computername "." $VHDService.Unmount($updateTarget) }
If you want to be able to run on Windows 7 or Windows 2008 R2 without the Hyper-V role, you would need to leverage diskpart, and basically dynamically create a short script to select the vdisk of the VHD, then attach it.