Relative Content

Tag Archive for powershellpowershell-cmdletpowershell-core

Powershell out-file -append silently skips a few rows when used inside foreach loop

I am trying to extract a representative sample of a 200MB csv file by writing the header and every 500th row to a new file for testers to use. My first attempt was knowingly sub-optimal but seemed valid for a 5 minute quick hack, as I relied on out-file -append to add each row matching the modulus condition to the destination file on network share, but what I found is that I had slightly fewer rows in the sample file than expected. Repeated runs produced slightly different numbers of rows in the destination file (expected 2014, actual ranged between 1992-2011).