I am quite new to PowerShell, and I am struggling with what should be a simple script.
I wish to move files within a source folder to a destination folder, if part of their filename matches strings within a text file.
Source = .\SourceFiles
Destination = .\DestinationFiles
FileNamesToMatch = .\FileNames.txt
Source contains the following:
I wish to move the files from Source to Destination based on a wildcard match from each string in FileNames.txt.
The following is code similar to what I want to achieve, however it is meant for a single string rather than the contents of a text file so it fails when passing it the variable $FileNamesToMatch:
$Source = .\SourceFiles $Destination = .\DestinationFiles $FileNamesToMatch = Get-Content .\FileNames.txt Get-ChildItem -Path $Source -Filter "*$FileNamesToMatch*" | Move-Item -Destination $Destination
I hope this makes sense! Thanks