Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Search Folders for Match and Delete Folders That Don't Contain Match

$
0
0

Hello,

I have about 8 folders that have various things copied into them throughout the day (Event vwr logs, text files, and .dmp files). What I am trying to figure out is how can I write a statement in Powershell that will search the 8 folders for .dmp files and then delete any folder that doesn't contain a .dmp file. 

I can use this for 1 folder but I am not sure how to write it so it would check each of the 8 folders. I could probably write 8 test-path statements in the script but I'm sure there is a better way to do it. 

if (!(test-path -path "\\s00readynas02\erp\Server Crashes\Current\Folder1\*.dmp")) {Remove-Item "\\s00readynas02\erp\Server Crashes\Current\*" } Else {}


TIA



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>