Attach a VHD in Windows 7

By searching through the web. I found some tutorial about attach a VHD in Hyper-V by PS using the code below:

$objVHDService = get-wmiobject -class "Msvm_ImageManagementService" -namespace "root\virtualization" -computername "."

$objVHDService.Mount("d:\virtuals\demo1\demo1.vhd")

I try this in Windows 7. But it show me "Invalid namespace".

Then I try to get the class only

$objVHDService = get-wmiobject -class "Msvm_ImageManagementService"
This time it show me "Invalid class". Is the PS in Hyper-V different to the one in Win 7 ?

December 19th, 2010 8:34am

Hyper-V is the hardware virtualization solution that is only available on Windows Server 2008/2008 R2.  You're trying to use the built-in virtualization in Windows 7 or have some other product loaded?
Free Windows Admin Tool Kit Click here and download it now
December 19th, 2010 1:12pm

As noted elsewhere Hyper-V and its associated WMI namespaces are only available with Hyper-V installed.

Another route would be to use the DISKPART.EXE command line tool. Running this from an elevated shell allows all of the GUI functions from Disk Management (and probably some more).

For usage for attaching a VHD enter

HELP ATTACH VDISK

from the DISKPART prompt.

December 19th, 2010 1:39pm

Since my Windows 7 is a fresh install (with some modification - hardening).

So I think I'm using the built-in virtualization in Windows 7 only.

Free Windows Admin Tool Kit Click here and download it now
December 20th, 2010 3:56am

Is that mean even Windows 7 has PowerShell included. But it has no PowerShell class/namespace for VHD management ?
December 20th, 2010 3:58am

Is that mean even Windows 7 has PowerShell included. But it has no PowerShell class/namespace for VHD management ?


Yes. There is no "root\virtualization" namespace in Windows 7, you can check it by open Computer Management, expand Services and Applications, right click WMI Control, click Properties, click Security. This namespace only be available on Windows Server 2008 R2 with Hyper-V installed.

Best Regards

Dale

Free Windows Admin Tool Kit Click here and download it now
December 20th, 2010 6:16am

$path = c:\xyz.vhd
$script = "SELECT VDISK FILE=`"$path`"`r`nATTACH VDISK"
$script | diskpart

December 20th, 2010 10:44am

I wish I could upvote KloinerFeigling83's answer more than once for command line attaching a VHD in Windows 7 using PowerShell!

I can't believe it was so hard until I found this!

  • Edited by E D F 13 hours 14 minutes ago
Free Windows Admin Tool Kit Click here and download it now
June 9th, 2015 1:59pm

I wish I could upvote KloinerFeigling83's answer more than once for command line attaching a VHD in Windows 7 using PowerShell!

I can't believe it was so hard until I found this!

  • Edited by E D F Tuesday, June 09, 2015 5:55 PM
June 9th, 2015 5:54pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics