Get 5 Events from this log

I have this script:

$DCs = [DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest() |
    Select-Object -ExpandProperty Sites |
        Select-Object -ExpandProperty Servers |
            Select-Object -ExpandProperty Name

$results = Invoke-Command -ComputerName $DCs {
    Get-EventLog -LogName 'DFS Replication'  -Newest 100 | Where-Object {$_.EventID -eq 1206} |
        Select-Object "EventID","MachineName","Message","TimeGenerated"
}

$results | Export-Csv -Path .\AllDCs_DFSLogs.csv -NoTypeInformation

…I really only want the first 5 events of that particular EventID. I put in “100” to cull through the log to at least find them, but how do I winnow exactly the ‘latest 5 of that EventID’?

thank you

JT,

Get-Eventlog is deprecated. Do not use it anymore. You should use Get-WinEvent instead.

How about this:

$results = 
Invoke-Command -ComputerName $DCs {
    $FilterHashTable = @{
        LogName = 'System'
        ID      = 43
    }
    Get-WinEvent -FilterHashtable  $FilterHashTable |
    Select-Object -Property ID, MachineName, Message, TimeCreated -First 5 
}
1 Like

Works great thanks Olaf