How to find and delete folders that contains specific string and more?

Hello,

I have a folder called c:\application, and a banch of other folders on C: called “application-copy”,“applicationbkp”,“_application” and so on…
C: folder contains offcourse some folder that don’t related to “application”.

I would like to delete all folders with the string “application” in its foldername without deleting the actual “c:\application”

Thank you

Aviram,
Welcome back to the forum. :wave:t4: … long time no see. :wink:

What have you tried so far? Please share your code.

Please keep in mind: this forum is for scripting questions rather than script requests. We do not write customized and ready to use scripts or solutions on request.

We expect you to make an own attempt to get your task done or to solve your problem. If you have done so already please document here what exactly you have done and show your code. Then we probably might be able to help you step further.

Hi, change my test directory and check this with -whatif.
If it is ok for you, remove -whatif.

$Dirs = get-childitem 'b:\PS_test\*' | where-object {($_.name -like "*applications*") -and ($_.name -ne 'applications')} 
Remove-Item $Dirs -force -whatif 

Hi
I done it with:
$toDelete gci -Path C:\ | Where-Object {$.Name -like “application” -and $.Name.Length -gt 11 }

Your way looks more clear
Thank you.

Get-ChildItem -Path c:\ |
    Where-Object -Property Name -NotMatch -Value '^application$'

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org <---- Click :point_up_2:t4: :wink: