【问题标题】:Use PowerShell to filter Event Logs and export to CSV使用 PowerShell 过滤事件日志并导出为 CSV
【发布时间】:2012-11-09 09:31:09
【问题描述】:

我有以下命令,它提供了我需要的信息,但我需要进一步过滤它:

Get-EventLog -LogName Security -ErrorAction SilentlyContinue | Select TimeWritten, ReplacementStrings | Export-Csv output.csv

这给出了许多这样的条目:

09/11/2012 08:09:27                {S-1-5-18, SYSTEM, NT AUTHORITY, 0x3e7...} 

我想删除 ReplacementStrings 中以 '{S-1-5' 开头的所有条目,但我尝试使用 Where-Object-notlike 没有任何区别!

我遇到的另一个问题是,如果没有添加Export-Csv output.csv,它会在屏幕上正常显示,但它会像这样写入文件:

"09/11/2012 09:22:05","System.String[]"

【问题讨论】:

    标签: powershell csv filter event-log


    【解决方案1】:
    Get-EventLog -LogName Security -ErrorAction SilentlyContinue | 
        Select TimeWritten, @{name='ReplacementStrings';Expression={ $_.ReplacementStrings -join ';'}} | 
        where {$_.ReplacementStrings -notmatch '^S-1-5'} | Export-Csv output.csv
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-18
      • 1970-01-01
      • 2023-03-13
      相关资源
      最近更新 更多