ondrovic
ondrovic

Reputation: 1175

Powershell List of Computers

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"

Upvotes: 2

Views: 247

Answers (1)

Cole9350
Cole9350

Reputation: 5570

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

Upvotes: 2

Related Questions