使用PowerShell过滤事件日志并导出为CSV

时间:2012-11-09 09:31:10

标签: powershell csv filter event-log

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

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...} 

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

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

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

1 个答案:

答案 0 :(得分:5)

Get-EventLog -LogName Security -ErrorAction SilentlyContinue | 
    Select TimeWritten, @{name='ReplacementStrings';Expression={ $_.ReplacementStrings -join ';'}} | 
    where {$_.ReplacementStrings -notmatch '^S-1-5'} | Export-Csv output.csv
相关问题