Check and Repair Disk Errors

This script runs chkdsk on each local drive to check for and repair disk errors. Use this during off-peak hours, as chkdsk may require a reboot.

# Check all local drives
$drives = Get-PSDrive -PSProvider FileSystem

foreach ($drive in $drives) {
    Write-Output "Checking drive $($drive.Name) for errors."
    chkdsk $($drive.Name): /F /R /X
}

• Explanation: The chkdsk command checks each drive, fixes errors (/F), attempts recovery of bad sectors (/R), and dismounts the volume if necessary (/X). Note that this may prompt a reboot for the system drive.

Last updated