Repair WindowsImage - PowerShell


Overview

The Repair-WindowsImage command is part of the Windows Recovery Environment (WinRE) and is used to repair Windows boot problems or file system corruption. It can be used to restore missing or damaged system files, as well as to rebuild the Windows Boot Manager (Bootmgr) or Master Boot Record (MBR).

Syntax

Repair-WindowsImage -ImageFilePath <string> -AssessmentOption <string> -RepairOption <string> [[-EnableRepairDisk] [-Path <string>] [-ScratchDirectory <string>] [-Verbose] [-WhatIf] [-Confirm] [<CommonParameters>]]

Options/Flags

  • -ImageFilePath: Specifies the path to the Windows image file (WIM) to be repaired.
  • -AssessmentOption: Specifies the type of assessment to perform on the Windows image. Valid values are RepairOnly (default), AssessOnly, and AutoRepair.
  • -RepairOption: Specifies the type of repair to perform. Valid values are None (default), SystemFilesOnly (repairs only system files), BootOnly (repairs only boot components), and Full (repairs both system files and boot components).
  • -EnableRepairDisk: Specifies that the repair should be performed on a repair disk.
  • -Path: Specifies the path to the repair disk or folder.
  • -ScratchDirectory: Specifies the path to the scratch directory that will be used for the repair.
  • -Verbose: Outputs detailed information about the repair process.
  • -WhatIf: Performs a simulation of the repair process without actually making any changes.
  • -Confirm: Prompts for confirmation before performing the repair.

Examples

1. Assess a Windows image for boot problems:

Repair-WindowsImage -ImageFilePath C:\Windows\System32\winre.wim -AssessmentOption AssessOnly

2. Repair only system files in a Windows image:

Repair-WindowsImage -ImageFilePath C:\Windows\System32\winre.wim -AssessmentOption RepairOnly -RepairOption SystemFilesOnly

3. Repair both system files and boot components in a Windows image:

Repair-WindowsImage -ImageFilePath C:\Windows\System32\winre.wim -AssessmentOption RepairOnly -RepairOption Full

Common Issues

  • “The operation is not supported on this type of file system.”: This error occurs if the Windows image file is not located on an NTFS file system. Repair-WindowsImage only supports NTFS file systems.
  • “The specified image is corrupted.”: This error occurs if the Windows image file is corrupted. Try repairing the image using the Windows Recovery Environment (WinRE) or a third-party imaging tool.
  • “The system cannot find the file specified.”: This error occurs if the path to the Windows image file is incorrect. Verify that the path is correct and that the file exists.

Integration

The Repair-WindowsImage command can be integrated into scripts or command chains to automate the repair of Windows images. For example, the following script repairs all Windows images in a specified directory:

$images = Get-ChildItem -Path C:\Windows\System32\WinRE\ -Filter *.wim
foreach ($image in $images) {
    Repair-WindowsImage -ImageFilePath $image.FullName -AssessmentOption RepairOnly -RepairOption Full
}
  • [Get-WindowsImage]
  • [New-WindowsImage]
  • [Set-WindowsImage]
  • [Remove-WindowsImage]