Get-Eventlog hangs when using EntryType

Welcome Forums General PowerShell Q&A Get-Eventlog hangs when using EntryType

This topic contains 4 replies, has 3 voices, and was last updated by

 
Participant
10 months, 2 weeks ago.

  • Author
    Posts
  • #90227

    Participant
    Points: -19
    Rank: Member

    Hi!
    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

    Participant
    Points: 59
    Rank: Member

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

    • #90236

      Participant
      Points: -19
      Rank: Member

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

  • #90251

    Participant
    Points: 0
    Rank: Member

    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

      Participant
      Points: -19
      Rank: Member

      Thank you Richard, I will check that out!

The topic ‘Get-Eventlog hangs when using EntryType’ is closed to new replies.