I am using PowerShell to dump some reports to CSV, and I would like to limit the size of the reports. When a report is generated I use...
Export-Csv -Path [path] -Append -NoTypeInformation
...which creates a file with a single header line, which is what I want. The issue is, as I add records, I would like to limit the file to the 1000 newest rows. So for instance if I have 1300 rows, how do I keep the header and get rid of lines 1-300 of data?
Select-Objectbefore exporting the data to csv file, or you output the csv data again and use aSelect-Objectwith par example a-First 1000or-Last 1000to recreate the csv.-Appendparameter ofExport-Csvis inefficient as the file gets larger and it is good to avoid using it if possible.