2

How can I make this use a list of servers

Tried doing $ComputerList = gc <list location> but it doesnt seem to be working correctly with one computer

$Start = (Get-Date).AddMinutes(-120)
$ComputerList = $env:ComputerName 
$Events = gc C:\Temp\ErrorCodes.txt

# Getting all event logs
Get-EventLog -AsString -ComputerName $Computername |
ForEach-Object {
# write status info
Write-Progress -Activity "Checking Eventlogs on \\$ComputerName" -Status $_

# get event entries and add the name of the log this came from
Get-EventLog -LogName $_ -EntryType Error, Warning -After $Start -ComputerName $ComputerName -ErrorAction SilentlyContinue |
  Add-Member NoteProperty EventLog $_ -PassThru | Where-Object {$Events -contains $_.eventid}

} |
# sort descending
Sort-Object -Property EventLog |
# select the properties for the report
Select-Object EventLog, EventID, TimeGenerated, EntryType, Source, Message 
# output into grid view window
Out-GridView -Title "All Errors & Warnings from \\$Computername"
Cole9350
  • 5,444
  • 2
  • 34
  • 50
ondrovic
  • 1,105
  • 2
  • 23
  • 40

1 Answers1

2

Force it to be an array.. Otherwise it will come in as a string if there is only one item

$ComputerList = @(gc c:\folder\computerlist.txt)

PowerShell: How can I to force to get a result as an Array instead of Object

Community
  • 1
  • 1
Cole9350
  • 5,444
  • 2
  • 34
  • 50