Script takes 5minutes in shell vs 30s in ISE – Why?

I have a script that imports a csv file and modifies a few fields and then exports it to a new csv file. The source file is 220k lines. When the script runs in the ISE, it runs in 30 seconds or so. When it runs in the shell, it takes 5+ minutes. Any thoughts on why?

Here’s the a relevant code snippet that has been sanitized:

$filename = "file.csv"$dfile = "$DailyFilesDir$filename" $ifile = "$iFiles$filename" [int]$i = "0" If ((Get-Item $dfile).length -gt 0kb) { Write-Host "Importing $filename....." $C = Import-CSV $dfile | Where-Object{$_."field1" -eq "No"} $C | foreach { $i++ Write-Progress -Activity "Processing..." -percentcomplete (($i / $C.Count) * 100) $_."Account" = $_."Account Name".replace(", "," ") if($_.Price -eq "") {$_.Price="1"} if($_.Quantity -eq "") {$_.Quantity=$_."Other Current Value"} if($_."Date" -eq "") {$_."Date"=$_."As of Date"} if($_."Unit" -eq "") {$_."Unit"="1"} } Write-Progress -Activity "Exporting $dfile" $C | select @{Name="A";Expression={$_."A-1"}},Symbol,"B","C",@{Name="D";Expression={[decimal]$_."Other Current Value"+[decimal]$_."E"}},"Price","Quantity","Date","Unit","Account Name","As Of Date","Number","field1" | Export-CSV $ifile -NoTypeInformation Write-Host "$filename processed, continuing...." } else { Write-Host "$filename is too small. There's a problem" pause } 

submitted by /u/Tuxhedoh
[link] [comments]

Leave a Reply