Move Files With Common Name

I have many .txt files in various folders with common name text like 123text, 222text222, text333, how do I move all of them to a new certain folder with that specific name as foldername

Thanks for reaching out. You should make an attempt to write the code and then tell us what troubles you are encountering. We’re here to help you, not write the code or the script for you. Take a look at regex and the -match operator.

From a general perspective you should be able to get all the files in the folders using Get-ChildItem then loop through those files, and check for a match based on whatever criterion you have, then if there’s a match, move the file to a new folder.

$files = Get-ChildItem "C:\Folder" -Filter *.txt -recurse 
Foreach-Object {
   $files = Where-Object {$_ -match '*TEXT*'} | move-item -destination C:\NEW_Folder
       }

You are overcomplicating this … this should do the trick

Get-ChildItem -Path 'C:\Folder' -Filter '*text*.txt' -Recurse |
    Move-Item -Destination 'C:\NEW_Folder'

You just might have to deal with duplicate names when you’re moving files from different source folders to one single destination folder