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

**URL:** <https://forums.powershell.org/t/how-can-i-restore-a-corrupted-vhdx-hd-by-using-power-shell/11824>\
**Category:** PowerShell Help\
**Created:** [December 24, 2018, 4:39am UTC](https://forums.powershell.org/t/how-can-i-restore-a-corrupted-vhdx-hd-by-using-power-shell/11824 "2018-12-24T04:39:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![aadam](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@aadam](https://forums.powershell.org/u/aadam)\
**Post date:** [December 24, 2018, 4:39am UTC](https://forums.powershell.org/t/how-can-i-restore-a-corrupted-vhdx-hd-by-using-power-shell/11824/1 "2018-12-24T04:39:19Z")

</div>

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)
- 

```auto

```

- CategoryInfo : InvalidOperation: (mount:String) , RuntimeException
- FullyQualifiedErrorId : MethodNotFound

can any body help me

---

<div class="post-metadata">

**Author:** ![kpatnayakuni](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kpatnayakuni/32/19_2.png) [@kpatnayakuni](https://forums.powershell.org/u/kpatnayakuni)\
**Post date:** [December 24, 2018, 8:09am UTC](https://forums.powershell.org/t/how-can-i-restore-a-corrupted-vhdx-hd-by-using-power-shell/11824/2 "2018-12-24T08:09:00Z")

</div>

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…

[pre]

$VHDXName=‘D:\Recuritment.vhdx’

Mount-DiskImage -ImagePath $VHDXName

[/pre]

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

[pre]

$VHDXName=‘D:\Recuritment.vhdx’

Mount-VHD -Path $VHDXName

[/pre]

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

[pre]

$VHDXName=‘D:\Recuritment.vhdx’

Dismount-DiskImage -ImagePath $VHDXName # With the Storage module

Dismount-VHD -Path $VHDXName # With the Hyper-V module

[/pre]

Thank you.

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [December 24, 2018, 8:50am UTC](https://forums.powershell.org/t/how-can-i-restore-a-corrupted-vhdx-hd-by-using-power-shell/11824/3 "2018-12-24T08:50:08Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![kpatnayakuni](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kpatnayakuni/32/19_2.png) [@kpatnayakuni](https://forums.powershell.org/u/kpatnayakuni)\
**Post date:** [December 24, 2018, 9:16am UTC](https://forums.powershell.org/t/how-can-i-restore-a-corrupted-vhdx-hd-by-using-power-shell/11824/4 "2018-12-24T09:16:12Z")

</div>

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

Please refer to Microsoft Docs.

> **[Msvm\_ImageManagementService class - Win32 apps](https://docs.microsoft.com/en-us/windows/win32/hyperv_v2/msvm-imagemanagementservice)**
>
> Manages the virtual media (.vhd, .vhdx, .iso, or .vfd files) for a virtual machine.

Thank you.

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [December 24, 2018, 9:47am UTC](https://forums.powershell.org/t/how-can-i-restore-a-corrupted-vhdx-hd-by-using-power-shell/11824/5 "2018-12-24T09:47:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kpatnayakuni](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kpatnayakuni/32/19_2.png) [@kpatnayakuni](https://forums.powershell.org/u/kpatnayakuni)\
**Post date:** [December 24, 2018, 10:26am UTC](https://forums.powershell.org/t/how-can-i-restore-a-corrupted-vhdx-hd-by-using-power-shell/11824/6 "2018-12-24T10:26:59Z")

</div>

Yes, you are right “AttachVirtualHardDisk” method serves the purpose here. Instead you can use strait CmdLet [pre] Mount-DiskImage [/pre]

Thank you

---

<div class="post-metadata">

**Author:** ![aadam](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@aadam](https://forums.powershell.org/u/aadam)\
**Post date:** [December 25, 2018, 6:22am UTC](https://forums.powershell.org/t/how-can-i-restore-a-corrupted-vhdx-hd-by-using-power-shell/11824/7 "2018-12-25T06:22:33Z")

</div>

> [@](#):
>
> 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

---

<div class="post-metadata">

**Author:** ![aadam](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@aadam](https://forums.powershell.org/u/aadam)\
**Post date:** [December 25, 2018, 6:28am UTC](https://forums.powershell.org/t/how-can-i-restore-a-corrupted-vhdx-hd-by-using-power-shell/11824/8 "2018-12-25T06:28:05Z")

</div>

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
- 

```auto
  + CategoryInfo : NotSpecified: (MSFT_DiskImage:ROOT/Microsoft/.../MSFT_DiskImage) [Mount-DiskImage], CimException
  + FullyQualifiedErrorId : HRESULT 0x80070570,Mount-DiskImage

```

how can i mount this hard

thanks alot

---

<div class="post-metadata">

**Author:** ![kpatnayakuni](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kpatnayakuni/32/19_2.png) [@kpatnayakuni](https://forums.powershell.org/u/kpatnayakuni)\
**Post date:** [December 25, 2018, 6:39am UTC](https://forums.powershell.org/t/how-can-i-restore-a-corrupted-vhdx-hd-by-using-power-shell/11824/9 "2018-12-25T06:39:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:33pm UTC](https://forums.powershell.org/t/how-can-i-restore-a-corrupted-vhdx-hd-by-using-power-shell/11824/10 "2024-05-16T20:33:30Z")

</div>


