Welcome › Forums › General PowerShell Q&A › Deleting file containing specific path
Does anyone know, if it is somehow possible to target files, that contains a path name accross multiple directories?
For an example:
Is it possible to create a deletion process that scans the paths of all files, and then deletes them if the path contains unwanted?
Currently i have no example of code to execute this, i am struggling to find documentation regarding if this is even possible.
Can anyone point me in the right direction? 🙂
you can always use Get-ChildItem with -Filter parameter. Below is an example.
Get-ChildItem -Path c:\RootFolder -Filter *unwanted* -Recurse -Directory
Save the output of the above expression in a variable and process further for deletion.
I suggest to read the help doc of Get-ChildItem and Remove-Item cmdlet.