A specialized PowerShell script designed to replace specific files on a "Live/Corrupted" drive with healthy versions from a "Recovery/Backup" drive.
This script is ideal for scenarios like Ransomware Recovery or Data Corruption. Instead of a bulk restore that might create duplicates or clutter, this script reads a list of specific filenames (e.g., from a log or a specific directory export) and performs a 1-to-1 replacement only if the file already exists on the destination.
- Source (Z:): Your Backup/Recovered drive (e.g., a mounted Veeam backup).
- Destination (W:): Your Live/Target drive containing the corrupted or encrypted files.
- The Logic:
- It reads a text file containing relative paths.
- It checks if the file exists in the Source.
- It checks if the file exists in the Destination.
- Crucial: It only performs the
Copy-Itemif the file is found in both locations, ensuring a 100% precise replacement.
- Create a file named
files.txton your desktop. - List the relative paths of the files you wish to restore (e.g.,
folder\subfolder\document.docx).
Open the script and modify the following variables to match your environment:
- Paths: Change the paths for
log.txtandfiles.txt. - Drive Letters: Adjust
$src(Source) and$dst(Destination) variables. - Path Logic: Adjust the
-replacelogic if your source folder structure differs from your destination.
Run the script in a PowerShell window with administrative privileges.
This script uses the -Force parameter to overwrite files. Always ensure you have a secondary backup before running mass-replacement scripts.