for each help

by Jan 27, 2011

This works great:

 foreach ($server in $ServerList)
     {$server; get-winevent -computername $server -Credential $Creds
-FilterHashTable @{ logname = "application","system"; StartTime =
(get-date).AddDays(-$Past); Level= 2,3}|
     ConvertTo-Html -Property LevelDisplayName, ID, ProviderName, Message ,LogName, TimeCreated -head $HTML|
     Out-File C:EventLogs.html -Append}


But this does not:

 foreach ($server in $ServerList)

     $logs=Get-WinEvent -ComputerName $server -listlog * |
Where {$_.IsClassicLog -eq 'True'} | Select-Object logname

    get-winevent -computername $server -Credential $Creds -FilterHashTable @{ logname = $logs     ConvertTo-Html -Property LevelDisplayName, ID, ProviderName, Message, LogName, TimeCreated -head $HTML|
     Out-File C:EventLogs.html -Append}



My goal is to have the server be asked what event logs it contains (as DC's have some different logs than file servers) the show me the error and warning from said logs….


Please show me the errors of my ways 🙂