每 1 小时将 Windows 日志导出到 csv

问题描述

我真的需要你的帮助,我已经制作了一个将日志导出到 csv 文件的脚本:

Set-Variable -Name EventAgeDays -Value 1
Set-Variable -Name CompArr -Value @("Localhost")
Set-Variable -Name LogNames -Value @("Security","Application","System")
Set-Variable -Name EventTypes -Value @("information","Error","Warning","FailureAudit","SuccessAudit")
Set-Variable -Name ExportFolder -Value "C:\"

$el_c = @()
$Now = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId($(Get-Date),[System.TimeZoneInfo]::Local.Id,'GMT Standard Time')
$startdate=$Now.adddays(-$EventAgeDays)
$ExportFile=$ExportFolder + "mx_sugus_poc_" + $Now.ToString("yyyy.MM.dd_hh.mm") + ".csv"

foreach($comp in $CompArr)
{
  foreach($log in $LogNames)
  {
    Write-Host Processing $comp\$log
    $el = get-eventlog -ComputerName $comp -log $log -After $startdate -EntryType $EventTypes -Message "*"
    $el_c += $el
  }
}

$el_sorted = $el_c | sort-object TimeGenerated
Write-Host Exporting to $ExportFile
$el_sorted|Select TimeGenerated,EntryType,Source,EventID,MachineName,UserName,Message | export-CSV $ExportFile -NoTypeInfo

另外,我更改了 GMT 格式的日期。

我想更改日志中的搜索,而不是每天每小时更改一次。

你能帮我解决这个问题吗???

非常感谢!!!

解决方法

$startdate=$now.adddays(-$EventAgeDays) 改为 $startdate=$now.addHours(-1)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...