Hello, so I’m trying to get involved with all the runspaces hype… but I can’t seem to figure it out ![]()
foreach ($file in $files) {
Write-Progress -Status "File Number $([array]::IndexOf($files, $file))" -Activity "Parsing Log Files" -PercentComplete (($([array]::IndexOf($files, $file)) / $files.Count) * 100)
# I assume write-progress is useless when using runspaces?? #
$SR = New-Object System.IO.StreamReader -ArgumentList $file.FullName
try {
while (($line = $SR.ReadLine()) -ne $null) {
if ($line -match 'A002') {
$line -replace ' +',"," | Out-File $tempFile -Append
}
}
}
finally {
$SR.Close()
}
}
So I have this code at the moment and I’m trying to figure out a way to parallel this block of code. I tried using workflows foreach -parallel, but it wasn’t really working properly, it was outputting a few lines every 30 seconds or so… So the whole idea is to parallel files parsing, not one file parsing ( I don’t think that makes sense). I’ve seen a few examples of runspaces here and there, but I can’t seem to figure out how to launch several runspaces and give each one a single file to chew on and how to return data from runspace. Out-file doesn’t work for some reason. Stuff like this also doesn’t
$contents = new-object System.Collections.ArrayList
foreach() {bla-bla-bla; [void] $contents.add($_.replace(somethingineedtodo))}
$contents
Any help appreciated, thanks!