Repair Vhdx Powershell May 2026

[Parameter(Mandatory=$true)] [string]$HealthyCopyPath,

# Get the volume letter (e.g., F:) chkdsk F: /f /r /x For non-structural corruption (e.g., block allocation issues): repair vhdx powershell

Repair-VHD -Path "C:\CorruptedVMs\server01.vhdx" -Path "D:\Backups\healthy_server01.vhdx" -Passthru param( [Parameter(Mandatory=$true)] [string]$VhdPath

catch Write-Warning "Repair-VHD failed: $($_.Exception.Message)" Write-Host "Attempting mount + chkdsk recovery..." $mountResult = Mount-VHD -Path $VhdPath -ReadOnly -PassThru -ErrorAction SilentlyContinue if ($mountResult) $disk = Get-Disk -Number $mountResult.Number -ErrorAction SilentlyContinue if ($disk) Get-Partition # Get the volume letter (e.g.

# Recreate the differencing disk from healthy parent $parentPath = "D:\BaseImages\parent.vhdx" $newChildPath = "E:\VMs\newchild.vhdx" New-VHD -ParentPath $parentPath -Path $newChildPath -Differencing Advanced Script: Auto-Repair with Backup Fallback <# .SYNOPSIS Attempts to repair a VHDX file, falling back to a backup copy. .DESCRIPTION Uses Repair-VHD if possible. If that fails, mounts the VHDX read-only, runs chkdsk, and then replaces with a backup if corruption persists. #> param( [Parameter(Mandatory=$true)] [string]$VhdPath,

Write-Warning "Automatic repair incomplete. Manual inspection required." | Error | Cause | PowerShell Fix | |-------|-------|----------------| | The VHDX is corrupt | Header or metadata damage | Use Repair-VHD with healthy copy | | The system cannot find the file specified | Path issue or missing parent (differencing) | Provide full absolute path | | Access denied | Permission or locked file | Run as Administrator; ensure no VM attached | | The parameter is incorrect | Fixed-size VHDX passed to Repair-VHD | Convert to dynamic first: Convert-VHD -Path file.vhdx -Destination dynamic.vhdx -VHDType Dynamic | | The VHDX chain is broken | Missing parent in differencing chain | Use Get-VHD -Path child.vhdx -ParentPath to locate parent; restore parent | Checking VHDX Health Without Repair # Health check function function Test-VHDXHealth param([string]$Path) try Select-Object Path, State, VhdFormat, VhdType, FileSize, Size catch Write-Error "Cannot read VHDX: $_"

$fixedVHD = Repair-VHD -Path "E:\Corrupt\data.vhdx" -Path "F:\Backups\data_clean.vhdx" -Passthru $fixedVHD | Format-List *