PowerShell processing of large CSV very slow - Is there a better way? -


using powershell , working through foreach loop. 1 of steps inside loop find match in csv file -

import-csv ".\ratecard.csv" | where-object{$($item.'from number') -match "^\+?($($_.destination))\w*$"} 

the foreach loop processing around 100,000 records month time period , completes within few minutes without csv lookup. after adding csv lookup can see taking 5-10 seconds each lookup. csv file has 40,000 rows , 10 columns.

while understand client side processing going slower, , should @ using sql, wondered if there faster way this. thought of using stream reader couldn't work out how match lookup.

any suggestions appreciated.

as mjolinor suggested, move import-csv outside foreach loop:

$ratecard = importcsv ".\ratecard.csv" foreach($item in $items){     if($ratecard.destination -contains $item.'from number'){         stuff     } } 

i added if/then function check if item's number found in csv's destination field.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -