How to Extend the Windows RE Partition Using PowerShell

KB5034441 is a WinRE security update that patches the Winre.wim image. The Recovery partition needs 250 MB of free space for the KB5034441 update to install correctly.

Almost every Windows 10 user has been affected by the KB5034441 error 0x80070643. You can extend the Recovery partition using the diskpart command-line. However, end-users might find that command-line procedure complicated.

So, here’s a PowerShell script from Microsoft that automatically extends the Recovery partition by 250 MB.

(Script source: Microsoft Learn)

Editor’s note: Before proceeding, please backup your Winre.wim image. Also, as a general precaution, backup important files to an external drive before modifying the disk partitions, even though Microsoft’s PowerShell script (.PS1) makes appropriate validations before resizing the Recovery partition.

Extend Windows RE Partition Using PowerShell

  1. First, restart Windows before you run the script. This is critical as there may be pending partition operations staged on your machine that must be finalized before the script can safely increase the WinRE partition size.
  2. Then, open an admin PowerShell and run:
    md C:\Winrefix\backup

    create folder - powershell

  3. Download winre.ps1 (zipped), unzip and extract the script file to the C:\winrefix folder.
    winre resize script
  4. In the admin PowerShell window, type:
    Set-ExecutionPolicy -ExecutionPolicy Unrestricted
  5. Press Y when asked for confirmation.
  6. Next, type the following commands:
    cd winrefix

    The above executes the winre.ps1 script.

    Sample output

    cmdlet winre.ps1 at command pipeline position 1
    Supply values for the following parameters:
    (Type !? for Help.)
  7. When prompted, type the backup folder path as follows, and press Enter:

    You’ll see an output similar to the following:

    Sample output

    cmdlet winre.ps1 at command pipeline position 1
    Supply values for the following parameters:
    (Type !? for Help.)
    BackupFolder: c:\winrefix\backup
    Start time: 06/03/2024 14:47:32
    Examining the system...
    Windows RE status:         Enabled
    Windows RE location:       \\?\GLOBALROOT\device\harddisk0\partition3\Recovery\WindowsRE
    System directory: C:\WINDOWS\system32
    ReAgent xml: C:\WINDOWS\system32\Recovery\ReAgent.xml
    Collecting OS and WinRE partition info...
    OS Disk: 0
    OS Partition: 2
    WinRE Partition: 3
    Disk PartitionStyle: MBR
    WinRE partition size info
      Partition capacity: 650113024
      Partition free space: 130801664
    WinRE Partition Offset: 209066131456
    WinRE Partition Type: Unknown
    OS partition size: 208960225280
    OS partition Offset: 105906176
    OS partition ends at: 209066131456
    WinRE partition starts at: 209066131456
    Backup Directory: [c:\winrefix\backup]
    Verifying if the WinRE partition needs to be extended or not...
    Summary of proposed changes
    Will shrink OS partition by 262144000
      Current OS partition size: 208960225280
      Target OS partition size after shrinking: 208698081280
    Unallocated space between OS and WinRE partition that will be used towards the new WinRE partition: 0
    Will extend WinRE partition size by 250MB
      WinRE partition: Disk [0] Partition [3]
      Current WinRE partition size: 650113024
      New WinRE partition size:     912257024
    WinRE will be temporarily disabled before extending the WinRE partition and enabled automatically in the end
    The contents of the old WinRE partition will be backed up to [c:\winrefix\backup]
    Please reboot the device before running this script to ensure any pending partition actions are finalized
    Would you like to proceed? Y for Yes and N for No: Y
  8. Press Y
    You’ll see the output similar to the following:

    Sample output

    Proceeding with changes...
    Note: To prevent unexpected results, please do not interrupt the execution or restart your system
    Loading [C:\WINDOWS\system32\Recovery\ReAgent.xml] ...
    Clearing stage location info...
    Saving changes to [C:\WINDOWS\system32\Recovery\ReAgent.xml]...
    Disabling WinRE...
    REAGENTC.EXE: Operation Successful.
    Verifying that WinRE wim exists in downlevel at default location
    Performing repartition to extend the WinRE partition ...
    Shrinking the OS partition to create a larger WinRE partition
    Resizing the OS partition to: [208698081280]...
    Target partition size: 208698081280
    Size of OS partition after shrinking: 208698081280
    Copying content on WinRE partition from [\\?\Volume{098cc206-0000-0000-0000-50ad30000000}\] to [c:\winrefix\backup]...
    Copying [\\?\Volume{098cc206-0000-0000-0000-50ad30000000}\recovery] to [c:\winrefix\backup\recovery]...
    Backup completed
    Deleting WinRE partition: Disk [0] Partition [3]...
    Creating new WinRE partition...
    Target size: 912257024
    Creating temporary diskpart script to create Recovery partition on MBR disk...
    Temporary diskpart script file: C:\Users\Ramesh\AppData\Local\Temp\ExtendWinRE_MBR_PowershellScript.txt
    Executing diskpart script...
    Diskpart script executed successfully
    Deleting temporary diskpart script file...
    New Partition index: 3
    Re-enabling WinRE...
    REAGENTC.EXE: Operation Successful.
    WinRE Information:
    Windows RE status:         Enabled
    Windows RE location:       \\?\GLOBALROOT\device\harddisk0\partition3\Recovery\WindowsRE
    WinRE Partition Index: 3
      Partition capacity: 912257024
      Partition free space: 392609792
    OS Information:
    OS partition size: 208698081280
    OS partition Offset: 105906176
    End time: 06/03/2024 14:48:56
    The contents of the old WinRE partition has been backed up to [c:\winrefix\backup]
    Successfully completed the operation
  9. To revert the script execution policy to default, type the following command in PowerShell:
    Set-ExecutionPolicy -ExecutionPolicy Restricted
  10. Press Y when asked for confirmation.

That’s it. The PowerShell script has successfully resized the Recovery partition by shrinking the OS partition. The Recovery partition should now be 250 MB larger than it was before.


Disk Management

Before resizing the Recovery partition:

recovery partition size - disk management

After extending the partition by 250 MB:

recovery partition size - disk management

PowerShell window

recovery partition extend - powershell output

recovery partition extend - powershell output

(Right-click on each image and click “Open in a new tab” to read the output in those screenshots.)

More information

  • The PowerShell script mentioned in this article works on both MBR and GPT-based disks.
  • If WinRE is disabled on the computer, the script doesn’t do anything.
  • If WinRE is located in the OS partition, the script does nothing, as no resizing is required.
  • The script backs up the old WinRE partition content to the specified backup folder. It uses the backup in case of failure to restore the original partition.
  • If the script detects more than 250 MB of free space in the WinRE partition, it doesn’t resize it.
  • If the WinRE partition is not after OS partition, it can’t extend the WinRE partition. Instead, it creates a new WinRE partition after the OS partition.
  • The script doesn’t proceed further if WinRE is located on the System partition.

I hope that this information helps.

One small request: If you liked this post, please share this?

One "tiny" share from you would seriously help a lot with the growth of this blog. Some great suggestions:
  • Pin it!
  • Share it to your favorite blog + Facebook, Reddit
  • Tweet it!
So thank you so much for your support. It won't take more than 10 seconds of your time. The share buttons are right below. :)

Ramesh Srinivasan is passionate about Microsoft technologies and he has been a consecutive ten-time recipient of the Microsoft Most Valuable Professional award in the Windows Shell/Desktop Experience category, from 2003 to 2012. He loves to troubleshoot and write about Windows. Ramesh founded in 2005.

Leave a Comment