locked
Query all top ten events for a event id on a Event Log RRS feed

  • Question

  • Hello,

    First let me say my Posh is very rudimentary and I am fairly new.

    I am trying to get all events on a list of servers and write them down on a CSV, so far I modify a bit a script I use for SQL commands from the dbatools.io module.

    $outfile = 'C:\out.csv'
    
    GET-Content C:\Servers.txt | ForEach-Object {Get-EventLog -LogName System -Newest 10 -ComputerName $_ | Where-Object {$_.EventID -eq 50, 140} |
    But I am bit lost, can anyone point me what I am doing wrong.


    Blog: www.sqlservertoolbox.blogspot.com.mx

    Wednesday, April 3, 2019 9:29 PM

Answers

  • I strongly recommend taking the time to learn basic PowerShell.

    Get-Content C:\Servers.txt | 
        ForEach-Object {
            Get-WinEvent -FilterHashTable @{LogName='System';ID= 50, 140} -Newest 10 -ComputerName $_
        }


    \_(ツ)_/

    • Marked as answer by Enrique AA Wednesday, April 3, 2019 10:55 PM
    Wednesday, April 3, 2019 10:03 PM

All replies

  • I strongly recommend taking the time to learn basic PowerShell.

    Get-Content C:\Servers.txt | 
        ForEach-Object {
            Get-WinEvent -FilterHashTable @{LogName='System';ID= 50, 140} -Newest 10 -ComputerName $_
        }


    \_(ツ)_/

    • Marked as answer by Enrique AA Wednesday, April 3, 2019 10:55 PM
    Wednesday, April 3, 2019 10:03 PM
  • Thanks was not aware of the use of WinEvent, just for others that come -Newest if not valid on this context -MaxEvents is.

    I sure do need to learn, thanks


    Blog: www.sqlservertoolbox.blogspot.com.mx


    • Edited by Enrique AA Wednesday, April 3, 2019 11:03 PM
    Wednesday, April 3, 2019 10:55 PM