How to Fetch the new event log from the previous event id

112 views Asked by At

I have a script which is fetching the event logs from multiple remote servers for the first time.For the second time it should check it is not the same eventID which i first fetch for every remote server or it should be greater from the previous eventID. SO every time it should not fetch the same event log.

How can i achieve this. Any Suggestions would be helpful

The Script:

#Give your local path on where you are saving server.txt file
$ComputerList = "E:\Event\servers.txt"

#Script Vaiables

$Computers = Get-Content $ComputerList | Where-Object { $_ }
$WindowslogName = "Application"
$WindowsMessageMatch = "Event 'Task Stopped'"
$TodaysDate = Get-Date
$TodaysDate.ToUniversalTime()

$AfterDate=Get-Date
$AfterDate.AddDays(-1)
$AfterDate.ToUniversalTime()

#Query Event Log
foreach($Computer in $Computers)
{
       Write-Host "Fetching Event Logs $Computer"
       $Event=Get-Eventlog -After $AfterDate  -Before $TodaysDate -LogName Application -ErrorAction SilentlyContinue -InstanceId 602 -Message "*Event 'Task Stopped'*" -Newest 1 -ComputerName $Computer
       $Event|Format-List * 
}
0

There are 0 answers