Creating a tail log with Powershell

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.

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

Leave a Reply