Get-Eventlog hangs when using EntryType

This topic contains 4 replies, has 3 voices, and was last updated by  Audun 3 months, 3 weeks ago.

  • Author
  • #90227


    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?

  • #90235

    Sam Boutros

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

    • #90236


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

  • #90251

    Richard Siddaway

    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.

    • #90280


      Thank you Richard, I will check that out!

You must be logged in to reply to this topic.