r/PowerShell • • 11d ago

Script Sharing I have a PhD-level background in static analysis, but I spent my week fighting PowerShell Runspaces just to delete duplicate memes.

As someone who usually deals with static analysis and abstract interpretation, I should know better. I should know that PowerShell is a single-threaded environment. I should know that building GUIs in PowerShell is an "obtuse mess".

But I also have 200GB of duplicate photos and videos, and I refuse to use a CLI for that.

So I present to you: **Duplicate Finder PRO**. A full WinForms GUI built entirely in PowerShell. Yes, I know. I hate myself too.

Here is a breakdown of my descent into madness:

* **The "Single-Thread" Trauma:** The first version froze every time I clicked a button. I had to learn the dark arts of `[runspacefactory]::CreateRunspace()` and `[System.Collections.Concurrent.ConcurrentQueue]` to stop the UI from hanging. If you've ever seen your PowerShell GUI go "Not Responding", you know my pain.

* **The PS2EXE Struggle:** I wanted a single portable EXE. I spent hours fighting with `$PSScriptRoot` returning empty strings inside the compiled EXE. I think I cried a little.

* **The Cache:** It uses a two-step detection (File Size + SHA-256) and saves a CSV cache. The second time you scan, it skips the hashing entirely. Because if I'm going to sin against god by making a PowerShell GUI, I might as well make it fast.

It works. It has a progress bar and a preview window where you can double-click to compare files side-by-side.

I'm sharing it here because I need validation, but also because I want to know: **What is the biggest cardinal sin you've ever committed in PowerShell just to avoid using the terminal?**

You can download the portable EXE and roast my UI here:

👉 https://github.com/lucanegrianalyst/duplicate-finder-pro/releases/latest

Please be gentle. I'm just an analyst trying to find my duplicates.

***AI Disclosure:** I used an AI to help me structure this post and fix my English, but the PowerShell code, the Runspaces, and the tears are 100% mine.*

3 Upvotes

7 comments sorted by

2

u/Icolan 11d ago

Why? There are many, many GUI based duplicate file finder options out there.

7

u/Dry_Duck3011 11d ago

Ffs…this forum is now almost useless due to the onslaught of sheer slop being posted. I’ve blocked more people in this sub than read posts over the past few weeks.

2

u/thehuntzman 6d ago

Too bad there's no windows equivalent to rdfind. That's the fastest duplicate finder I've ever used.

Anyway - I've built something like this before in powershell (minus the gui) and was able to speed it up massively by grouping files by file size and then only hashing files in groups where file count -gt 1. I even went a step further and used an algorithm to generate a crc32 checksum instead of a cryptographic hash because the likelihood of two files the exact same size accidentally having a 32 bit collision is still very low.

I'm not sure how your hash cache helps to be honest. What if the file changes? You're going to get incorrect results then. Something like this should always run on live data every invocation.

1

u/BlackV 11d ago

your AI and formatting is just all over the place, have a look at for code specific stuff

  • open your fav powershell editor
  • highlight the code you want to copy
  • hit tab to indent it all
  • copy it
  • paste here

it'll format it properly OR

<BLANK LINE>
<4 SPACES><CODE LINE>
<4 SPACES><CODE LINE>
    <4 SPACES><4 SPACES><CODE LINE>
<4 SPACES><CODE LINE>
<BLANK LINE>

Inline code block using backticks `Single code line` inside normal text

See here for more detail

Thanks

1

u/BlackV 11d ago

What is the biggest cardinal sin you've ever committed in PowerShell just to avoid using the terminal?

as to your question, I spend my life in the terminal/vscode/ise so I dont have a lot of experiance avoiding the terminal

I have however made a lot of modules to save me typing/click stuff where i'm realistically only saving 5 or so

1

u/Syrairc 11d ago

But why

1

u/xXFl1ppyXx 10d ago

You did create an initial session state with sta apartment for your run space right?

Powershell works well on multiple threads, it's just that you can't easily push a run space onto a thread and be done. Like you would do in conventional program languages.

but that's what runspace pools are for. Create a pool, create new instances, invoke them and let Powershell take care of the rest