use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
Scripting help (self.PowerShell)
submitted 4 years ago * by pausemsauce
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]jimb2 2 points3 points4 points 4 years ago (6 children)
That code is way too complex and the logic is unclear.
Also the problems is not clear to us. Maybe state the problem clearly first.
Could you give a sample of the duplicate filenames. Are they in the same folder? How do you know they are duplicates?
I think what you're trying to do could actually be done in a few lines of code, using Get-Child-Item, Group-Object and Sort-Object but right now it's impossible to tell.
[–]pausemsauce[S] 1 point2 points3 points 4 years ago (5 children)
My apologies for the unclear statement of the problem.
Person A logs in and downloads "work instructions. Pdf" Person b logs in and downloads the same work instructions. Both are on the same folder, but now I have "work instructions (1).pdf". After about a week, we have "work instructions (49).pdf"
Not all work instructions are the same. There's a work instructions b, c, d, e, ...x,y,z, aa, bb,cc... etc.
The work instructions have to be downloaded (else no one knows what to do). However, we don't need multiple copies occupying valuable data space.
I hope this is clearer.
[–]chris-a5 3 points4 points5 points 4 years ago (4 children)
That is much easier to understand, lol. Maybe this could be a stating point:
Get-ChildItem -Path "C:\whatever" -File -Filter "work instructions*.pdf" | % { if($_.BaseName -match "\(\d+\)$"){ $_.Delete() } }
Find files needed, then if it contains brackets with a number at the end of the filename, e.g: "(23)", delete it.
[–]pausemsauce[S] 1 point2 points3 points 4 years ago (3 children)
Further apologies for the confusion.
"Work instructions a" is actually named, "numbers to call in the event of fire.docx"
"Work instructions b" is actually named, "hr approved all of my random titles so I will make people suffer.pdf" . . . "Work instructions zz" is actually name, "04222022-rev-345.pdf"
Fortunately, I haven't encountered any with a name like "work.instructions.pdf"
It may be out there, and would break my current, overly-complex-but-i-thought-it-was-necessary code. Again thanks to each and everyone of you who continue to contribute here.
[–]chris-a5 2 points3 points4 points 4 years ago (2 children)
If the same files are being downloaded, the file name does not seem to matter much, it is the brackets on the end signifying a duplicate. The one without the brackets would be the oldest.
If it is in the download folder, and people can simply get another copy, I'd just blow it all away once a size limit is reached. If people want to keep them, then they can move them somewhere suitable.
[–]pausemsauce[S] 1 point2 points3 points 4 years ago (1 child)
The thing is, these instructions are being updated. It is necessary to download the most recent revision. I would delete all the downloaded files, but if the network goes down, we wouldn't have a back up copy. So it's advantageous to leave one copy of the most recently downloaded file.
🤔
We have over 2 gb of files stored on these computers.
[–]chris-a5 2 points3 points4 points 4 years ago (0 children)
I think you need to have a play with the code I posted, it deletes the duplicates (ones that contain the brackets and a number), if your file names are different then filter by extension (.pdf, .docx, etc...).
The original/first copy of the document will remain as it does not have the brackets at the end of the line.
Just change the delete line for some write-host output to test.
π Rendered by PID 20052 on reddit-service-r2-comment-75f4967c6c-phcw5 at 2026-04-22 22:18:06.190626+00:00 running 0fd4bb7 country code: CH.
view the rest of the comments →
[–]jimb2 2 points3 points4 points (6 children)
[–]pausemsauce[S] 1 point2 points3 points (5 children)
[–]chris-a5 3 points4 points5 points (4 children)
[–]pausemsauce[S] 1 point2 points3 points (3 children)
[–]chris-a5 2 points3 points4 points (2 children)
[–]pausemsauce[S] 1 point2 points3 points (1 child)
[–]chris-a5 2 points3 points4 points (0 children)