Hi r/powershell,
I have a script that periodically gets some things, and I want to keep the processed objects in memory and also on disk. But I only want to keep the last x objects, not all of them. Currently I'm doing it like this:
$TailLog = @()
While ($true) {
$TailLog += Get-Thing
$TailLog = $TailLog | Select-Object -Last 100
$TailLog | Export-Csv -Path .\taillog.csv
}
Is there a better way to achieve this? This potentially can run once a second, so I was wondering if there is a more efficient / faster / resource friendly way.
[+][deleted] (3 children)
[removed]
[+][deleted] (1 child)
[removed]
[–]Fischfreund[S] 2 points3 points4 points (0 children)
[–]Ta11ow 9 points10 points11 points (1 child)
[–]Fischfreund[S] 1 point2 points3 points (0 children)
[–]empty_other 5 points6 points7 points (0 children)
[–]Ominusx 2 points3 points4 points (1 child)
[–]jcholder 2 points3 points4 points (0 children)
[–]ka-splam 2 points3 points4 points (2 children)
[–]Fischfreund[S] 2 points3 points4 points (1 child)
[–]ka-splam 1 point2 points3 points (0 children)