You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
James Downes (@JamesDownes5) , were you thinking that batching the reading with -ReadCount would allow you to force garbage-collection after every N objects in order to relieve the memory pressure?
The desired process is: Read Chunk of Input File > Convert to Hashtable based on First Column > Write/Append Data to File > Repeat until End of Input File
The data doesn't even need to be turned into a PSObject, could just be left as Strings.
Import-Csv .\IMPROTANT_DATA.csv | group ID | foreach {
$_.Group | Export-Csv -NoTypeInformation -UseQuotes Never -Path ".\$($_.Name).csv"
}
But the issue is that you are using Group-Object which would need to have all the data in memory to group elements so you won't gain anything by doing this.
The @PowerShell/wg-powershell-cmdlets discussed this. We believe the right way to address the memory issue due to PSNoteProperty and the garbage collector is to enable -AsHashTable switch for both ConvertFrom-Csv and Import-Csv as described in #11027. We will close this issue as a dupe of that one and reactive the linked issue.
Activity
JamesDownes5 commentedon Jul 7, 2025
I am happy to implement this, I just need some direction and showing where the current Import-Csv implementation is
MartinGC94 commentedon Jul 7, 2025
Are you sure it doesn't already stream things if you use the pipeline?
Import-Csv | foreach {# Do somethingmklement0 commentedon Jul 7, 2025
Indeed, MartinGC94, it streams, yet it's still possible to run out of memory.
Related:
Import-CSV has very high filesize-to-memory consumption ratio of around 50 #7603
Feature Request: Add OutputType parameter to Import-Csv #8862
James Downes (@JamesDownes5) , were you thinking that batching the reading with
-ReadCountwould allow you to force garbage-collection after every N objects in order to relieve the memory pressure?JamesDownes5 commentedon Jul 7, 2025
This is what I currently have:
MartinGC94 How would I go about making this a complete pipeline?
This is my attempt at batching:
The desired process is: Read Chunk of Input File > Convert to Hashtable based on First Column > Write/Append Data to File > Repeat until End of Input File
The data doesn't even need to be turned into a PSObject, could just be left as Strings.
MartinGC94 commentedon Jul 7, 2025
You could do it like this:
But the issue is that you are using
Group-Objectwhich would need to have all the data in memory to group elements so you won't gain anything by doing this.mklement0 commentedon Jul 7, 2025
If runtime performance isn't a concern, you can avoid
Group-Objectas follows, which opens and closes each output file for every object written to it:If you still run out of memory, try calling
[GC]::Collect(); [GC]::WaitForPendingFinalizers()after every N objects.iRon7 commentedon Jul 8, 2025
You might use the steppable pipeline for this and directly stream the results into multiple output pipelines.
For a full explanation see: https://devblogs.microsoft.com/powershell-community/mastering-the-steppable-pipeline/#multiple-output-pipelines
See also:
#20123Tee-Object -ProcessSteveL-MSFT commentedon Nov 19, 2025
The @PowerShell/wg-powershell-cmdlets discussed this. We believe the right way to address the memory issue due to PSNoteProperty and the garbage collector is to enable
-AsHashTableswitch for bothConvertFrom-CsvandImport-Csvas described in #11027. We will close this issue as a dupe of that one and reactive the linked issue.microsoft-github-policy-service commentedon Nov 20, 2025
This issue has been marked as duplicate and has not had any activity for 1 day. It has been closed for housekeeping purposes.