none
Attach a VHD in Windows 7

    Question

  • 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 ?

    Sunday, December 19, 2010 8:34 AM

Answers

  • 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


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
    Monday, December 20, 2010 6:16 AM
    Moderator
  • 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?
    Sunday, December 19, 2010 1:12 PM
    Moderator
  • 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.


    Richard J Cox
    Sunday, December 19, 2010 1:39 PM

All replies

  • 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?
    Sunday, December 19, 2010 1:12 PM
    Moderator
  • 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.


    Richard J Cox
    Sunday, December 19, 2010 1:39 PM
  • 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.

    Monday, December 20, 2010 3:56 AM
  • Is that mean even Windows 7 has PowerShell included. But it has no PowerShell class/namespace for VHD management ?
    Monday, December 20, 2010 3:58 AM
  • 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


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
    Monday, December 20, 2010 6:16 AM
    Moderator
  • $path = c:\xyz.vhd
    $script = "SELECT VDISK FILE=`"$path`"`r`nATTACH VDISK"
    $script | diskpart
    
    
    Monday, December 20, 2010 10:44 AM
  • 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 9, 2015 5:55 PM
    Tuesday, June 9, 2015 5:54 PM