Search code examples
powershellevent-logget-winevent

Log Monitoring of Multiple Computers with Get-WinEvent


From the line of code below, is there a way to call a .txt file for a list of computers to be looked at? I want it to look for logs in not just one computer but from a list of computers.

$StartDate = (get-date).AddHours(-12)
Get-WinEvent -FilterHashtable @{logname="System"; Level=1,2,3; starttime=$StartDate} -ErrorAction SilentlyContinue

Hope to hear from you soon! Thanks.


Solution

  • Since the -ComputerName parameter of the Get-WinEvent cmdlet does only accept a string, you probably have to iterate over the list:

    $StartDate = (get-date).AddHours(-12)
    
    Get-Content 'computers.txt' | ForEach-Object {
        Get-WinEvent -ComputerName $_ -FilterHashtable @{logname="System"; Level=1,2,3; starttime=$StartDate} -ErrorAction SilentlyContinue    
    }