How to Build a Custom Sort Script for QPhotoRec files using Powershell

Paul Connacher 1 Reputation point
2021-07-27T10:33:24.363+00:00

I have a randomly grouped and large numbers of improperly-names files that were recovered from a backup drive which come a total size of 280 GB. I need to get as many of the original file names back as well as backup creation date (which is recovered each file), the software publisher of the file, the version name of the file, the architecture of the file (only if available), and finally string these properties together to create a new file name that properly identifies each file in the recovered backup files directory.

Next I need to categorize all files into different home directory structures (see outline below), by first creating my directory structure on the backup medium, and then copying to each subdirectory a list of file extensions that would match content to each directory, the program should ask me to either accept a default group of file types for each directory or specify a comma-separated list of custom file types to be copied to into each directory. The directory structure to be used is provided in the outline below.

Directory Structure:
./Backups/WBK_27_Jul_2021/ ....
Downloads/
Documents/
Music
Pictures/
Videos/
VirtualBox VMs/
VMware/
Misc/

Upon successful grouping, verification must be done to make sure each file in the copied directories on the backup HDD are equivalent to their counterparts on local machine’s SDD.

If verification is passed 100 percent, then the module must proceed to deleted all of the recovered contents on the local machine SDD; if not passed 100 percent, the script must recopy the files that did not verify correctly and re-verify these files. Once all files copied verify 100 percent, then the module can proceed with deleting the recovered contents on the local machines HDD.

Detailed outline of how the module must run:

  • eliminate recovered files that are not > 0 bytes (as these would be empty files),
  • reorder the files by extension type in a directory called /home/sorted_data/by_ext/*
  • rename all JPEG and other files by calling a external tool such as exiv2,
  • remove all duplicate files by calling a external tool such as fdupes,
  • manipulate information provided in the File Properties dialog box to create a file name:

FileName_PublisherName_.VersionNumber_Arch_BK_FileBackupCreationDate.ext

E.g. Microsoft.Windows.10.Pro_1909_64-bit_BK_25_06_2021.iso,

  • create the following directory structures on backup HDD as per spec above,
  • copy related file extensions into each directory (use common sense),
  • verify each file copied into folder on the backup HDD,
  • remove the ~/sorted_data/* upon 100 percent successfully file copy verification.

If one can manipulate the File properties dialog a Microsoft Windows Machine with PowerShell and my backup has mixed Windows and Linux file types, would it possible to write one PowerShell Module under PowerShell 7.x on my Linux host to manipulate both Microsoft Windows file types and properties and the Linux file type and properties. This would make life ideal and much easier for me.

I believe the total execution time of this PowerShell Module would be much shorter than if I had had to write the same script in bash or ksh.

Now that PowerShell is supported on both Microsoft Windows and Linux, this task should not be so difficult to achieve. My only problem is I am very new to PowerShell and its language intricacies.

Please may you advise me on accomplishing the above outlined Module to achieve the tasked detailed above.

Your assistance would be highly appreciated.

Chio,
PaulTheScott.

Windows for business Windows Server User experience PowerShell
Windows for business Windows Server User experience Other
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.