Powershell to find the number of an "Event Occurance" has occured in Eventlog RRS feed

  • Question

  • Case: I am administering an (awful) website which I have found out that whenever the number of "unhandled exceptions" in the code (Event 1309) exceeds 45 the web application pool needs a recycle. 

    I found out that this i part of the [Message] property.

    Event code: 3005 
    Event message: An unhandled exception has occurred. 
    Event time: 19/06/2019 11:28:27 
    Event time (UTC): 19/06/2019 09:28:27 
    Event ID: 3466a6f632244889b07eae95f25ece14 
    Event sequence: 7194 
    Event occurrence: 27 
    Event detail code: 0 

    My aim will be to 
    1 Check the count of Event Occuence in Message Property
    2 If count is higher than 45 
        Recycle Application Pool

    Trial code:
    --> Get the latest event 
    Get-Eventlog -LogName Application -Newest -1 | Where-Object {$_.EventID -eq 1309}

    So - how to I search the Message property to find the Event Occurence number? 

    Any help appreciated.

    mercredi 19 juin 2019 10:28

Toutes les réponses