If you're tired of downloading countless utility apps to manage the storage on your PC, you'll be happy to know that there's a way to identify duplicate files on your device while only using built-in tools. After all, incidents like the recent hijacking of CPUID's download site show that even trusted sources can carry risks.

Since Windows doesn't have a dedicated GUI utility for finding duplicate files, the trick uses a handy PowerShell script. No downloads or setup required. Since it also doesn't require any third-party tools, it's the perfect solution for privacy-focused users who would rather avoid downloading additional tools.

How to get Powershell to identify file duplicates

You just need to enter the right script

PowerShell users have created a variety of scripts to help identify duplicate files over the years. This specific script calculates the hash for files within a specific folder and then groups files that have the same hash (and therefore the same content). This is helpful since it doesn't rely on file names, which you may have changed.

It then lists all groups where the same hash is detected more than once. You can see the full script below:

Get-ChildItem -Path "$env:USERPROFILE\Downloads" -Recurse -File |
 Get-FileHash |
 Group-Object Hash |
 Where-Object Count -gt 1 |
 ForEach-Object {
 "`nDuplicate group:"
 $_.Group | Select-Object Path
 }

If you want to scan a specific folder, replace "$env:USERPROFILE\Downloads" with the path for the folder you want. For example, I changed the script to look at my Documents and Photos folders as well. If you want to look at a folder in a different directory, then you can simply enter the full file path — for example, "C:\Users\Megan\Documents".

Once the script is done running, PowerShell will include a list of file paths under Duplicate group. You can use these details to search for the files using File Explorer (or in my case, a File Explorer alternative), and delete them.

The script can take some time to run if you have a large folder or a slow PC, so you may need to wait a few minutes to see the results in PowerShell. However, rather than trying to select an entire drive, I recommend using it for specific folders where duplicates are likely — such as your Downloads, Documents, and Photos folders.

Making your duplicate files easier to keep track of

Get PowerShell to export the results

Cleaning up your files may take some time if you've built up duplicates over a large period of time. I know that my own PC is full of downloads I've repeatedly saved from email attachments. So what do you do if you don't want to rerun the script every time you want to do a bit of digital spring cleaning?

You can adjust the PowerShell script to export its results to a CSV file so that you can revisit its results over multiple occasions. This can be done with the Select-Object and Export-Csv cmdlets appended to the original script.

To export the duplicate file paths to a CSV file that you can use with Excel or other spreadsheet software, you can use the following script:

Get-ChildItem -Path "$env:USERPROFILE\Downloads" -Recurse -File |
 Get-FileHash |
 Group-Object Hash |
 Where-Object Count -gt 1 |
 ForEach-Object {
 $_.Group | Select-Object Hash, Path
 } |
 Export-Csv -Path "$env:USERPROFILE\Desktop\duplicates.csv" -NoTypeInformation

This will save the CSV to your Desktop in a file named duplicates.csv. You can adjust the script to change the location or name of the file. However, you should note that it takes some time for PowerShell to export the generated information, and you may see the icon for the file before it's actually ready to view.

If you encounter an error that says PowerShell could not find the directory for the export, try a different folder. This could be due to a permissions issue.

Once the file is ready, you'll have a document that includes the paths of all your duplicate files.

When does using a GUI makes more sense?

A dedicated app works better for some use cases

Credit: 

While it is pretty easy to just paste and adjust the PowerShell script to find your duplicate files, there are times that a dedicated storage management app may work better. The most notable example is when you want to scan entire drives quickly. For this, you may want to use something like WizTree, which can identify duplicate files on your drives.

I also found that the script doesn't always work well for folders where you may have an excessive number of duplicates. This is because PowerShell only displays so much in its window, so you may scroll up the maximum amount and still not see all the items that were listed. This happened when I scanned my Documents folder, since it includes some of the folders for my self-hosted services.

I'd mostly recommend this trick for people who are comfortable using PowerShell and who don't want to use a third-party app to scan files on their PC.

👁 PowerShell and Windows PowerShell
6 PowerShell scripts to automate and speed up your workflow

When you work through the CLI you save a lot of time. Here are PowerShell scripts to speed your workflow.

Windows best tricks are sometimes the least known

There are plenty of buried tools in Windows that provide great functionality but aren't always easy to find. PowerShell is one of the biggest examples of this, probably due to the learning curve involved.

I personally think it would be great if Windows improved its own storage analysis tools to help users get a better idea of which files are duplicates and taking up space on their drives. For now, though, this trick can help you get a handle on your storage.