I have PowerShell script that I found on GitHub here. I am trying to export security audit logs that have a specific Event ID rather than exporting all logs to a .csv file. I am new to PowerShell and can't really seem to find any further information on next steps or how I should approach this. I imagine that the change will have to do with the Get-WinEvent -LogName $($EventType) | Export-CSV "$LogOutputCSVFilePath"
Line of code, however, i am not sure what the change would be. Any help is appreciated.
My Current Code
# Capture the script start time
$ScriptStartTime = Get-Date
# Set output location for CSV files.
$LogOutputDirectory = 'C:\Users\myuser\Desktop'
# Define Windows event log types to export.
$EventTypesToExport = @('Security')
foreach ($EventType in $EventTypesToExport)
{
# Build the file path for the current log topic.
$LogOutputTopic = "Windows Event Log - $EventType"
$CurrentTimeUTC = Get-Date -Format FileDateTimeUniversal
$LogOutputFileName = "$CurrentTimeUTC - $LogOutputTopic"
$LogOutputCSVFilePath = "$LogOutputDirectory\$LogOutputFileName.csv"
# Create a CSV version of the log data.
Write-Output "Creating CSV version of Windows event log of type $EventType."
Write-Output 'Target CSV file path:'
Write-Output "$LogOutputCSVFilePath"
Get-WinEvent -LogName $($EventType) | Export-CSV "$LogOutputCSVFilePath"
Write-Output 'Finished creating CSV file.'
}
# Calculate script run time.
$ScriptEndTime = Get-Date
$ScriptDuration = New-Timespan -Start $ScriptStartTime -End $ScriptEndTime
Write-Output "Log export process execution time: $ScriptDuration"
I am currently operating on Windows 10. Any help is appreciated!
Note: You can view these logs by going to the Event Viewer application on windows, selecting "Windows Logs" and then selecting "Security".