Author Posts

December 29, 2017 at 11:48 am

I'm working on a script that I'm going to run as a daily scheduled task. The script creates a htm-file with information from several servers. Among other things, I want to list error logs for the last 7 days from servers listed in $servers.

My case is this. When I run the following command, it's all good, and it gives me the logs I'm asking for:

Get-EventLog -ComputerName $servers -LogName System -After (Get-Date).AddDays(-7) -Before (Get-Date) -Newest 5|
    Select-Object MachineName, TimeWritten, EntryType, Source, Message

If I add "-EntryType Error", PowerShell hangs, and after a while it times out:

Get-EventLog -ComputerName $servers -LogName System -EntryType Error -After (Get-Date).AddDays(-7) -Before (Get-Date) -Newest 5|
    Select-Object MachineName, TimeWritten, EntryType, Source, Message

Why is this happening? Is there a better way to get error logs from several servers?

December 29, 2017 at 1:47 pm

You're trying to pull too much data. Try to pull data in smaller chunks..

December 29, 2017 at 1:52 pm

Probably. Any suggestion how to pull the data in smaller chunks?

December 29, 2017 at 3:18 pm

I've just successfully run your data gathering part of the code
Get-EventLog -LogName System -EntryType Error -After (Get-Date).AddDays(-7) -Before (Get-Date) -Newest 5

As you're only pulling the newest 5 records I don't think its too much data. I'd try to run the command on individual servers to see if there is an issue with one machine that's causing the problem.

December 29, 2017 at 7:18 pm

Thank you Richard, I will check that out!