从网上找到的代码非常好用,第一个导出数据到csv文件,第二个直接保存到html格式。
Get-Eventlog -ComputerName computer1 -LogName application -After (Get-Date).Adddays(-1) -EntryType Error,Warning | Export-csv d:\application_logs.csv
$Servers = "yourcomputer1",'"yourcomputer2" try { $Arr1 = Get-EventLog System -Entrytype Error -computer $Servers -After (Get-Date).AddDays(-1) | select MachineName,EventID,TimeGenerated,EntryType,Message,Source | ConvertTo-HTML -Fragment } catch [System.InvalidOperationException] { Write-Host "Uh uh, a error occured" } finally { #$CSS = get-content c:\style.css $head1 = "<title>Application Event Logs for Errors</title><style>$CSS</style>" ConvertTo-HTML -Body "$Arr1" -head $head1 | Out-File d:\System_Event_Logs.html }