Moving files if the filename contains a keyword in an external text file.

I’m trying to script the following process. If a file in a given folder contains a keyword, which I have in a text file, one keyword per line, then move it to another location. I’m still learning PS so I found a snippet that I thought would be close enough to use but it doesn’t work. No errors, just doesn’t do any sorting. Would anyone be so kind to help me out here?

$List = Get-Content C:UsersDownloadskeywords.txt

$Source = "C:UsersDownloadssource"

$Destination = "C:UsersDownloads$((Get-Date).ToString('yyyy-MM-dd'))destination"

foreach ($file in $List) {

$file_to_move = Get-ChildItem -Path $Source -Filter $record -Recurse -ErrorAction SilentlyContinue -Force | % { $_.FullName}

if ($file_to_move) {

Move-Item $file_to_move $Destination



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

Leave a Reply