So say you want to look at the last 3 thing in the eventlog for type application, from all the desktops on the lan. my problem is, the $a below makes an array (i think), and i want to write that to a file. right now it "works" but just spits out a few blank lines per machine. if $msg = is commented out, i get this "Exception calling "Join" with "2" argument(s): "Value cannot be null."
$servers = "machine1, "machine2"
$date = ( get-date ).ToString('yyyyMMdd')
$file = New-Item -type file "c:\temp\$date-test1.txt" -Force
$msg = ""
foreach($server in $servers){
Write-Host "Connect to $server..."
add-content $file "$server $date"
$a = Get-EventLog -Logname application -ComputerName $server -EntryType warning -newest 3 |
Format-Table -Wrap -Property Source,Message -Autosize
foreach($element in $a)
{[string]::join($element, $msg)}
Write-Host $msg
#add-content $file $msg
}