Home Forums Programming Powershell Reading Event Log: speeding up with If Exists equivalent? RE: Reading Event Log: speeding up with If Exists equivalent?

  • The performance issue is probably down to it being a huge log. I believe that if you know the source as well that this would filter it quicker.

    Also, I would be concerned that the message criteria is not being used as the last filter by Get-EventLog (I do not know either way). To check this you could change the filter by message out of the Get-EventLog call e.g.

    if(Get-EventLog -ComputerName GDC-WEB-P01 -LogName Application -EntryType Error,Warning -After ((Get-Date).addminutes(-5)) -Source "I DO NOT KNOW" | Where {$_.Message -eq "*Exception message: Specified cast is not valid.*")}

    Or event just temporarily remove it to see how long it takes without it.

    Please note that I think that the comparison of message with the string is not using the wildcard in the above example code so would not work.

    DISCLAIMER: Personally, I would not recommend as a long term resolution the recycling the AppPool due to a code defect.

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!