Skip to content

Repository files navigation

📦 DriveTools

A PowerShell module for auditing, organizing, deduplicating, and maintaining large external drives (3 TB+).

PowerShellPesterLicense: MIT


✨ Features

FeatureDescription
Fast AuditRecursively scans a drive and exports file metadata to CSV
Hash CachingStores SHA256 hashes in a JSON cache; only rehashes files that have changed
Auto-CategorizationMoves files into Projects / Media / Archives / Uploads / System folders based on extension and keyword patterns
Duplicate ResolutionDetects exact duplicates via hash; keeps the newest copy and removes the rest
CleanupRemoves empty directories, reports duplicate groups, compresses the Archives folder
Visual Tree MapGenerates a Unicode tree of the drive saved to a .txt file
Real-Time StatusGet-DriveStatus returns the currently running operation, start time, and details
Scheduled MaintenanceRegisters a Windows Scheduled Task to run audits automatically (Daily or Hourly)
WPF GUIOptional graphical launcher for all operations — no command line required

🗂️ Repository Layout

DriveTools/
├── DriveTools.psd1 # Module manifest
├── DriveTools.psm1 # Module implementation
├── DriveTools.GUI.ps1 # WPF graphical launcher
├── public/ # Public functions (autoloaded)
│ └── Start-DTAuditGui.ps1
├── src/
│ └── UI/
│ └── MainWindow.xaml # WPF window layout
├── lib/ # SQLite database dependencies
│ ├── System.Data.SQLite.dll
│ └── x64/
│ └── SQLite.Interop.dll
├── tests/
│ └── DriveTools.Tests.ps1 # Pester test suite
├── tools/
│ └── Invoke-DriveBenchmark.ps1 # Performance benchmark script
├── profile-snippet.ps1 # PowerShell profile snippet
└── README.md

⚡ Installation

Option A — Manual (recommended for personal use)

$dest="$env:USERPROFILE\Documents\PowerShell\Modules\DriveTools"New-Item-Path $dest-ItemType Directory -Force
Copy-Item DriveTools.psd1, DriveTools.psm1, DriveTools.GUI.ps1 -Destination $destCopy-Item public, src, lib -Destination $dest-Recurse -Force

Option B — Clone and install

git clone https://github.com/you/DriveTools.git
Set-Location DriveTools
.\Install.ps1 # copies module to the user module path

Verify installation

Import-Module DriveTools
Get-Module DriveTools |Select-Object Name, Version, ExportedFunctions

🚀 Quick Start

Import-Module DriveTools
# 1. Audit the drive$csv=Invoke-DriveAuditFast-RootPath M:\ -IncludeHashes
Write-Host"Report saved to $csv"# 2. Preview categorization without moving anythingInvoke-DriveCategorize-DryRun
# 3. Apply categorizationInvoke-DriveCategorize# 4. Find and remove duplicates (dry-run first!)Resolve-DriveDuplicates-DryRun
Resolve-DriveDuplicates# 5. Clean up empty foldersInvoke-DriveCleanup-RemoveEmptyDirectories -ReportDuplicates
# 6. View a tree map of the driveShow-DriveVisualMap-MaxDepth 3# 7. Schedule nightly maintenanceRegister-DriveMaintenanceTask-Schedule Daily
# 8. Monitor long-running operationsGet-DriveStatus

🖥️ WPF Graphical User Interface

For users who prefer a visual interface, DriveTools includes a complete WPF Graphical Launcher. It is designed to be highly responsive, running all background drive traversal and hash-computation tasks asynchronously so the UI thread never hangs.

Tip

The GUI is powered by a precompiled C# producer-consumer engine (AuditEngine) utilizing BlockingCollection to decouple disk I/O from computation.

🚀 Launching the GUI

Import-Module DriveTools
Start-DTAuditGui-ScanPath M:\ -CsvLogPath C:\path\to\log.csv

✨ Key Features

  • Asynchronous Execution: Traverses the file system and computes SHA256 file hashes in parallel worker threads without blocking the window interface.
  • Dynamic Progress Updates: A decoupled progress monitor updates the active folder/file display every 250ms.
  • One-Click Operations: Run fast audits, preview auto-categorization, search/remove duplicates, and clean up empty directories without using the command line.

📋 Command Reference

Invoke-DriveAuditFast

Scans a drive and exports a CSV with file metadata.

-RootPath <string> Drive or folder to scan (default: M:\)
-OutputCsvPath <string> Destination CSV path
-IncludeHashes <switch> Compute SHA256 for every file

Update-DriveHashCache

Builds or refreshes a JSON hash cache; unchanged files reuse their stored hash.

-RootPath <string> Drive root
-CachePath <string> Path to HashCache.json

Invoke-DriveCategorize

Moves files into category folders based on extension and keyword matching.

-RootPath <string> Drive root
-CategoryMap <hashtable> Custom map (category → pattern list)
-DisableDefaultCategoryMap <switch> Skip the built-in category map
-DryRun <switch> Log actions without moving files

Default CategoryMap:

CategoryTriggers
ProjectsUnity, Project, Source, .sln, .csproj, Perseus
Media.wav, .mp3, .flac, .mp4, .mov, .mkv, .jpg, .png, .psd, .ai
Archivesbackup, export, .zip, .rar, .7z, .bak
UploadsUPLOADS, upload, .torrent, .nfo
Systeminstaller, setup, .msi, .exe, .dll, .log

Resolve-DriveDuplicates

Hashes all files, groups identical hashes, keeps the newest copy.

-RootPath <string> Drive root
-DryRun <switch> Log what would be deleted without deleting

Invoke-DriveCleanup

Composite cleanup: empty directories, duplicate reports, archive compression.

-RemoveEmptyDirectories <switch> Delete zero-item folders
-ReportDuplicates <switch> Log duplicate groups to the log file
-CompressArchives <switch> Zip the Archives\ subfolder

Show-DriveVisualMap

Renders a Unicode tree of the directory structure.

-RootPath <string> Root to map
-MaxDepth <int> Recursion limit (default: 3)
-OutputPath <string> Where to save the .txt file

Register-DriveMaintenanceTask

Registers a Windows Scheduled Task that calls Invoke-DriveAuditFast automatically.

-TaskName <string> Task name (default: DriveMaintenance)
-Schedule <string> Daily | Hourly

Get-DriveStatus

Returns the currently active operation, start time, and last-update timestamp.


📁 Log Files

All operations write to daily log files:

%USERPROFILE%\Documents\DriveToolsLogs\DriveTools_YYYY-MM-DD.log

The SQLite Hash cache database is stored at:

%USERPROFILE%\Documents\DriveToolsLogs\DriveTools_HashCache.db

🧪 Running Tests

Requires Pester 5.

Install-Module Pester -Force -SkipPublisherCheck
Invoke-Pester .\tests\DriveTools.Tests.ps1 -Output Detailed

⚙️ Configuration

You can override the default drive root and log path in your profile or before importing the module by editing the module variables after import:

Import-Module DriveTools
# Point to a different drive
(Get-Module DriveTools).Invoke({ $Script:Drive_DefaultRoot='E:\' })

Or supply -RootPath on every call.


🤝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/my-feature
  3. Add Pester tests for any new functions
  4. Open a pull request

📄 License

MIT — see LICENSE.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages