I guess I'm the only one interested in this problem. :)
I was very disappointed and I found it difficult to believe that it could be that slow. Since my experience with so many commands being very quick I figured there had to be a PowerShell solution to speed it up.
Thanks to the Measure-Command cmdlet, I timed the different pieces and determined it was all in the write-host. I looked at how I could eliminate the write-host command. I settled on the following:
$ParsedFile = import-csv pat_delete.csv
$OutFile = @()
foreach ($x in $ParsedFile)
{$OutFile += `
"12 4"+`
$x.id_number+`
($x.tcode+" ").substring(0,6)+`
(get-date $x.tdate -uFormat %Y%m%d)+`
'CP'+`
$x.pcode+`
$x.pcode
}
Set-Content -value $OutFile TestOut.txt
I couldn't run it on the same workstation, so the workstation I'm currently on is slower when running this script. The original file (against 4000 records) runs in 21.754 seconds on this workstation (AMD 6400 X2).
The updated script, not using write-host, now runs in 3.8 seconds.
Original using write-host: TotalSeconds : 21.7544045
Modified using foreach with Set-Content: TotalSeconds : 3.8205268
I tried using the faster example using where-object instead of foreach but it took 4.1 seconds. If someone has already figured all this out I would love a link to it.
It's not instantaneous but it certainly is much better. It goes to show it doesn't hurt to try doing things in different ways. You might be surprised.
Thanks,
Bruce