【问题标题】:Export windows logs to csv each 1 hour每 1 小时将 windows 日志导出到 csv
【发布时间】:2023-03-20 19:38:01
【问题描述】:

我真的需要你的帮助,我已经制作了一个将日志导出到 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 格式。

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

你能帮帮我吗???

非常感谢!!!

【问题讨论】:

  • 每小时和每天运行时遇到了什么问题?
  • 同意道格,可能更适合它。

标签: powershell csv days


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-03
    • 2021-01-18
    • 2018-08-02
    • 2019-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多