Powershell for deleting files with specific characters in the name.
Been attempting to learn Powershell, slowly. Needed help with this. Got part of it working but not fully until someone fixed it.
get-childitem -recurse | Where-Object name -Like ‘(2)‘ | ForEach-Object { remove-item -LiteralPath $_.fullname -whatif }
A shorter version
get-childitem -recurse -filter ‘*(2)*’ | remove-item -whatif
The -whatif will run the command but not execute it so NOTHING will be delete. It will just show you what it would do IF you executed the command.
I used this as my sister had loads of photos that I had to back up with
0dd123.jpg, Odd123 (2).jpg
Which was going to be an arse to go through and delete all the (2) copies.
Be aware if you are copying this script from my site because the ‘ are formatted different on the site and I believe if you paste them into Powershell it may not work. Just go and manually replace the ‘. They look exactly the same but the code behind them is somewhat different. I’ve had this happen a few times with code I’ve copied from somewhere that had ‘ in it.