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

nei*_*man 4 csv powershell filter event-log

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

Get-EventLog -LogName Security -ErrorAction SilentlyContinue | Select TimeWritten, ReplacementStrings | Export-Csv output.csv
Run Code Online (Sandbox Code Playgroud)

这提供了许多条目,例如:

09/11/2012 08:09:27                {S-1-5-18, SYSTEM, NT AUTHORITY, 0x3e7...} 
Run Code Online (Sandbox Code Playgroud)

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

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

"09/11/2012 09:22:05","System.String[]"
Run Code Online (Sandbox Code Playgroud)

Jac*_*kie 5

Get-EventLog -LogName Security -ErrorAction SilentlyContinue | 
    Select TimeWritten, @{name='ReplacementStrings';Expression={ $_.ReplacementStrings -join ';'}} | 
    where {$_.ReplacementStrings -notmatch '^S-1-5'} | Export-Csv output.csv
Run Code Online (Sandbox Code Playgroud)