1

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.

lapsantos
  • 69
  • 1
  • 9

1 Answers1

1

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    
}
Martin Brandl
  • 56,134
  • 13
  • 133
  • 172
  • I've tried the one you gave but received the error, `Get-Winevent : The RPC server is unavailable`. Also, it worked on the local machine but not on the other ones on the computers.txt. – lapsantos Sep 20 '16 at 06:55
  • This is probably another topic, just search for the message and you will find ways to solve it. – Martin Brandl Sep 20 '16 at 07:00
  • Tried using IP addresses instead of computer names and it seems to work fine. Will update this thread once done with futher testing. Thanks, Martin! – lapsantos Sep 20 '16 at 07:16
  • You are welcome. Please consider to accept the answer – Martin Brandl Sep 20 '16 at 07:17