I need to copy files dependent on content. So I get all files, read the content and ask a regex if it is valid. After that I want to copy the file to a certain directory. My problem is, that there are a lot of source files, so I need to execute this in parallel.
I cannot use PowerShell ForEach-Object Parallel Feature because we are using Powershell Version < 7.0. Using a workflow is way to slow.
$folder = "C:\InputFiles"
workflow CopyFiles
{
foreach -parallel ($file in gci $folder *.* -rec | where { ! $_.PSIsContainer })
{
//Get content and compare against a regex
//Copy if regex matches
}
}
CopyFiles
Any ideas how to run this in a parallel manner with Powershell?
Get-Contentwill be a bad choice if you want the highest speed. - stackprotector