将Windows事件日志转换为文本或CSV

时间:2020-10-08 16:42:50

标签: powershell event-log

我是新来的,我有一个问题。我正在尝试从Windows获取原始事件日志(应用程序,系统,安全性)并将其导出到文本或CSV文件。

您会认为这很简单,但是使用PowerShell却无法正确完成。

如果我进入Windows事件日志屏幕并选择另存为...:

1

接下来,我选择另存为.txt。如果我打开该文件,它看起来像这样:

2

这正是我要使用Powershell进行的操作,但我做不到。即使与我最好的朋友google.nl仍然是一个问题。 有人可以帮我吗?

2 个答案:

答案 0 :(得分:0)

根据您提供的信息,我认为您正在要求Export-Csv cmdlet

# Set the destination filepath
$appLogsCsvPath = "C:\temp\appLogs.csv"
# grab the first 100 events in the application log
$first100Events = Get-EventLog -LogName Application | 
    Select-Object -First 100

# Export the events to a csv at the previously defined path
# When converting or exporting csv items in PowerShell
# I recommend always including the -NoTypeInformation switch,
# without it, it adds information to the csv that more often than not, messes it up.
$first100Events | 
    Export-Csv -Path $appLogsCsvPath -NoTypeInformation -UseCulture

# Opens the csv
ii $appLogsCsvPath

更多高尔夫版本

Get-EventLog -LogName Application | Select -First 100 | Export-Csv "C:\temp\appLogs.csv" -NoTypeInformation -UseCulture

编辑:在Export-Csv中添加了-UseCulture开关以说明语言环境设置

答案 1 :(得分:0)

我们得到 3 种事件类型:使用以下命令获取所有系统、安全和应用程序窗口 evnetlogs :

Get-EventLog -LogName security | Export-Csv "C:\temp\security-Logs.csv" -NoTypeInformation -UseCulture

Get-EventLog -LogName system | Export-Csv "C:\temp\system-Logs.csv" -NoTypeInformation -UseCulture

Get-EventLog -LogName Application | Export-Csv "C:\temp\Aplication-Logs.csv" -NoTypeInformation -UseCulture

检查每行在提到的Path中生成的CSV文件