Delete all folders containing a specific folder

One of the users I support had an issue with SCCM that generated a whopping 2 million folders with names like “00007071d068a78642” and “f1444fef524f1bc26b5b” which contain a folder called “Sandbox” which is empty. All of these folders are on the root of his C: drive as well as a second HD he has.

While I could hunt for his data, transfer it, and then reimage the machine, I was wondering if it’s possible (or worthwile) to write a powershell script that would check to see if a folder contains the folder “sandbox” and then remove it. Is this something better handled by robocopy?

I am a relatively new tier 1 here and I was hoping to use this as an exercise in scripting but to be truthful I’m not sure where to start. I could see using Remove-Item to remove all the sandbox folders, but how do I remove the folder that’s one level up and has a random name?

submitted by /u/Cd4plus
[link] [comments]

Leave a Reply