I have a folder with a bunch of .txt files. I want to iterate through them and check if any of them contains a keyword stored in an array of strings. If one match is found I want to store the file in a new folder named after the match. For example, I am checking if the word "OVERTIME" is in one of my text files; if a match is found I want to save the file in a new folder titled "OVERTIME". I intend on using move-item to move the file from the current folder to the new one that way the file gets deleted from the old folder. Below is my initial code; I am not sure how to set up the nested loop and how I can check if there is a match.
$reports_name = @('MYTIME','NOTIME','OVERTIME')
Get-ChildItem "C:\Users\My_User\Desktop\test" -Filter *.txt |
Foreach-Object {
$content = Get-Content $_.FullName
foreach($line in $content) {
if($line -in $reports_name){
move-item $content -Destination C:\Users\My_User\Desktop\$line
}
}