Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Utilize Bootrec for Windows: A Guide with PowerShell and Batch Script Examples

Bootrec.exe is a powerful command-line tool in Windows used for troubleshooting and repairing the Master Boot Record (MBR), Boot Sector, Boot Configuration Data (BCD), and other critical boot-related components. Understanding how to use Bootrec can be essential for system administrators and IT professionals when dealing with boot issues, such as a corrupted MBR or missing BCD.

In this guide, we will explore the functionalities of Bootrec and provide practical examples of how to use it through PowerShell and Batch scripts. This will help you automate the repair process and integrate it into your system recovery toolkit.

Examples:

Example 1: Using Bootrec via Command Prompt (CMD)

To use Bootrec, you need to access the Command Prompt with administrative privileges. This is typically done through the Windows Recovery Environment (WinRE).

  1. Accessing WinRE:

    • Restart your computer and press F8 (or another key specified by your computer manufacturer) to access the Advanced Boot Options menu.
    • Select "Repair your computer" and choose your keyboard layout.
    • Log in with an administrator account.
  2. Running Bootrec Commands:

    • Open Command Prompt from the System Recovery Options menu.
    • Execute the following commands to repair the boot issues:
bootrec /fixmbr
bootrec /fixboot
bootrec /scanos
bootrec /rebuildbcd

Example 2: Automating Bootrec with a Batch Script

You can create a Batch script to automate the Bootrec commands. This script can be saved on a USB drive and run from the Command Prompt in WinRE.

  1. Creating the Batch Script:
    • Open Notepad and enter the following commands:
@echo off
echo Repairing MBR and Boot Sector...
bootrec /fixmbr
bootrec /fixboot
echo Scanning for Windows installations...
bootrec /scanos
echo Rebuilding BCD...
bootrec /rebuildbcd
echo Boot repair complete.
pause
  1. Saving the Script:

    • Save the file with a .bat extension, for example, bootrepair.bat.
  2. Running the Script:

    • Boot into WinRE and open Command Prompt.
    • Navigate to the location of the script on your USB drive and run it:
X:\> bootrepair.bat

Example 3: Running Bootrec Commands via PowerShell

While Bootrec is a command-line tool, you can invoke it from a PowerShell script if you prefer working with PowerShell.

  1. Creating the PowerShell Script:
    • Open Notepad and enter the following PowerShell commands:
Write-Host "Repairing MBR and Boot Sector..."
Start-Process -FilePath "bootrec.exe" -ArgumentList "/fixmbr" -Wait
Start-Process -FilePath "bootrec.exe" -ArgumentList "/fixboot" -Wait
Write-Host "Scanning for Windows installations..."
Start-Process -FilePath "bootrec.exe" -ArgumentList "/scanos" -Wait
Write-Host "Rebuilding BCD..."
Start-Process -FilePath "bootrec.exe" -ArgumentList "/rebuildbcd" -Wait
Write-Host "Boot repair complete."
  1. Saving the Script:

    • Save the file with a .ps1 extension, for example, bootrepair.ps1.
  2. Running the Script:

    • Boot into WinRE and open Command Prompt.
    • Navigate to the location of the script on your USB drive and run PowerShell:
X:\> powershell.exe -File bootrepair.ps1

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.