|
Repair-VHD -Path "C:\CorruptedVMs\server01.vhdx" -Path "D:\Backups\healthy_server01.vhdx" -Passthru
Optimize-VHD -Path "C:\VHDX\suspect.vhdx" -Mode Full If a differencing VHDX is corrupt and its parent is healthy: repair vhdx powershell
[Parameter(Mandatory=$false)] [string]$BackupPath = "$env:TEMP\vhdx_backup_$(Get-Date -Format 'yyyyMMdd_HHmmss').vhdx" ) if (-not (Get-Module -ListAvailable -Name Hyper-V)) Write-Error "Hyper-V PowerShell module is required." exit 1 Repair-VHD -Path "C:\CorruptedVMs\server01
[Parameter(Mandatory=$true)] [string]$HealthyCopyPath, # Get the volume letter (e.g.
# Get the volume letter (e.g., F:) chkdsk F: /f /r /x For non-structural corruption (e.g., block allocation issues):
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: $_"