I only want the first event based on source...

Hi all,
I am hoping this is going to be a simple fix but I have been racking my brains with this simple query all day.
I am trying to make a list of a single entry per remote host of just one result of the most recent event based on a particular source.
Basically I am using get-eventlog within a script block as using get-eventlog within a loop is far too slow from a source machine.
Anyway, I have the script working to my liking now except I cannot seem to list ony the last event that happened, rather than all events in the log, does anyone know how to do this, I played around with ‘-newest 1’ but when using this my sript did not return anything at all :frowning:

Please find the script below:

$FinalList = @()
$CurrentSystem = @()
$Machine = get-content servers.txt
foreach ($Server in $Machine)
Write-Host $Server
$CurrentSystem = Invoke-Command -computername $Server -ScriptBlock{
get-eventlog -logname system | where-object {$_.Source -eq 'pvscsi'} | select-object machinename,source,eventid,message,timegenerated
write-host $CurrentSystem
$FinalList += $CurrentSystem
$FinalList | export-csv ServersWithPvsciEvents.csv

Many thanks.

Add “-first 1” to Select-Object?

That’s it, excellent!
Thanks Don.