{"id":2016,"date":"2022-02-11T12:39:39","date_gmt":"2022-02-11T12:39:39","guid":{"rendered":"https:\/\/stevenwhiting.com\/blog\/?p=2016"},"modified":"2022-02-11T12:45:25","modified_gmt":"2022-02-11T12:45:25","slug":"powershell-for-deleting-files-with-specific-characters-in-the-name","status":"publish","type":"post","link":"https:\/\/stevenwhiting.com\/blog\/?p=2016","title":{"rendered":"Powershell for deleting files with specific characters in the name."},"content":{"rendered":"\n<p>Been attempting to learn Powershell, slowly. Needed help with this. Got part of it working but not fully until someone fixed it.<\/p>\n\n\n\n<p>get-childitem -recurse | Where-Object name -Like &#8216;<em>(2)<\/em>&#8216; | ForEach-Object { remove-item -LiteralPath $_.fullname -whatif }<\/p>\n\n\n\n<p>A shorter version<\/p>\n\n\n\n<p>get-childitem -recurse -filter &#8216;*(2)*&#8217; | remove-item -whatif<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>I used this as my sister had loads of photos that I had to back up with<\/p>\n\n\n\n<p>0dd123.jpg, Odd123 (2).jpg<\/p>\n\n\n\n<p>Which was going to be an arse to go through and delete all the (2) copies.<\/p>\n\n\n\n<p>Be aware if you are copying this script from my site because the &#8216; 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 &#8216;. They look exactly the same but the code behind them is somewhat different. I&#8217;ve had this happen a few times with code I&#8217;ve copied from somewhere that had &#8216; in it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8216;(2)&#8216; | ForEach-Object { remove-item -LiteralPath $_.fullname -whatif } A shorter version &hellip; <a href=\"https:\/\/stevenwhiting.com\/blog\/?p=2016\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[333],"class_list":["post-2016","post","type-post","status-publish","format-standard","hentry","category-it-notes","tag-powershell"],"_links":{"self":[{"href":"https:\/\/stevenwhiting.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2016","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stevenwhiting.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stevenwhiting.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stevenwhiting.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/stevenwhiting.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2016"}],"version-history":[{"count":2,"href":"https:\/\/stevenwhiting.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2016\/revisions"}],"predecessor-version":[{"id":2020,"href":"https:\/\/stevenwhiting.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2016\/revisions\/2020"}],"wp:attachment":[{"href":"https:\/\/stevenwhiting.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2016"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stevenwhiting.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2016"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stevenwhiting.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2016"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}