how can i restore a corrupted VHDX HD by using power shell

Welcome Forums General PowerShell Q&A how can i restore a corrupted VHDX HD by using power shell

This topic contains 8 replies, has 3 voices, and was last updated by

 
Participant
3 weeks ago.

  • Author
    Posts
  • #131310

    Participant
    Points: -9
    Rank: Member

    high every body

    i have a problem with  vhdx corrupted via email and i need to repair it by using Power shell  i wrote

    $VHDXName='D:\Recuritment.vhdx'

    then

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

    then i wrote

    $result=$VHDservice.mount($vhdName)

    i got the following massage:

    Method invocation failed because [System.Management.ManagementObject] does not contain a method named 'mount'.
    At line:1 char:1
    + $result=$VHDservice.mount($vhdName)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (mount:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

    can any body help me

  • #131322

    Participant
    Points: 211
    Helping Hand
    Rank: Participant

    Hi Aadam,

    Which version of PowerShell are you using? The above script works only with PowerShell 2.0, if you are using the higher PS Version, use the commands below...

    
    $VHDXName='D:\Recuritment.vhdx'
    
    Mount-DiskImage -ImagePath $VHDXName
    
    

    Mount-DiskImage function comes with the Storage module, if you have Hyper-V PowerShell modules is installed and imported, you can Mount-VHD CmdLet.

    
    $VHDXName='D:\Recuritment.vhdx'
    
    Mount-VHD -Path $VHDXName
    
    

    To dismount the VHD/DiskImage you can use the following commands

    
    $VHDXName='D:\Recuritment.vhdx'
    
    Dismount-DiskImage -ImagePath $VHDXName       # With the Storage module
    
    Dismount-VHD -Path $VHDXName       # With the Hyper-V module
    
    

    Thank you.

  • #131333

    Participant
    Points: 1,086
    Helping Hand
    Rank: Community Hero

    Its not depended on PowerShell version, its with WMI and will work with later versions as well. The problem here is the Mount method is not seen in the available method list for this class, but its documented in MSDN.

    $VHDservice | Get-Member -MemberType Method
    
  • #131334

    Participant
    Points: 211
    Helping Hand
    Rank: Participant

    Please do not follow the MSDN topics, most of them are outdated.

    Please refer to Microsoft Docs.

    https://docs.microsoft.com/en-us/windows/desktop/hyperv_v2/msvm-imagemanagementservice

    Thank you.

  • #131336

    Participant
    Points: 1,086
    Helping Hand
    Rank: Community Hero

    Thanks, that one is outdated and the method to mount seems to be like AttachVirtualHardDisk()

  • #131349

    Participant
    Points: 211
    Helping Hand
    Rank: Participant

    Yes, you are right "AttachVirtualHardDisk" method serves the purpose here. Instead you can use strait CmdLet

     Mount-DiskImage 

    Thank you

  • #131456

    Participant
    Points: -9
    Rank: Member

    Mount-DiskImage function comes with the Storage module, if you have Hyper-V PowerShell modules is installed and imported, you can Mount-VHD CmdLet.

    Thanks alot for your kind support

  • #131459

    Participant
    Points: -9
    Rank: Member

    i used : Mount-VHD -Path $VHDXName
    and i had the following massage :
    Mount-DiskImage : The file or directory is corrupted and unreadable.
    At line:1 char:1
    + Mount-DiskImage -ImagePath $VHDXName
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (MSFT_DiskImage:ROOT/Microsoft/.../MSFT_DiskImage) [Mount-DiskImage], CimException
    + FullyQualifiedErrorId : HRESULT 0x80070570,Mount-DiskImage
    how can i mount this hard

    thanks alot

  • #131462

    Participant
    Points: 211
    Helping Hand
    Rank: Participant

    Then, in that case, create a VM, attach this VHD and start the VM, mostly it will scan and fix the issues while the operating system is booting. If it is still not resolved then you need to depend on some command line tools available online. Thank you.

You must be logged in to reply to this topic.