Created
November 25, 2025 12:23
-
-
Save scottglew/3154b2929946f1bf56c42ea5aac3e6f7 to your computer and use it in GitHub Desktop.
PowerShell script to export Sophos Firewall Authentication events from Fastvue Syslog log files to a CSV report.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| extract-sophos-auth-events.ps1 | |
| Export Sophos Firewall Authentication events from Fastvue Syslog log files. | |
| - Looks for yesterday's log file in $logPath with name pattern *-yyyy-MM-dd.log | |
| - Filters for log_component="Firewall Authentication" | |
| - Outputs a CSV with: | |
| Time, Event Type, Severity, Message, User Name, Source, Status | |
| #> | |
| # ======================== | |
| # Configurable variables | |
| # ======================== | |
| # Folder containing the Sophos log files for this firewall | |
| # Example: 'C:\ProgramData\Fastvue\Syslog Server\Logs\192.168.20.100' | |
| $logPath = 'C:\path\to\sophos\syslog\files' | |
| # Folder to write the CSV reports into | |
| $outputPath = 'C:\Firewall Authentication Reports' | |
| # Optional: you can override this if you want a specific date | |
| # By default it uses yesterday's date (for scheduling at 12:05am) | |
| $reportDate = (Get-Date).AddDays(-1) | |
| # ======================== | |
| # Derived values | |
| # ======================== | |
| $logDateString = $reportDate.ToString('yyyy-MM-dd') # matches filename date portion | |
| $logFilePattern = "*-$logDateString.log" | |
| # Find the log file for the report date | |
| $logFile = Get-ChildItem -LiteralPath $logPath -Filter $logFilePattern -ErrorAction SilentlyContinue | | |
| Sort-Object LastWriteTime -Descending | | |
| Select-Object -First 1 | |
| if (-not $logFile) { | |
| Write-Error "No log file found matching '$logFilePattern' in '$logPath'." | |
| exit 1 | |
| } | |
| Write-Host "Using log file: $($logFile.FullName)" | |
| # ======================== | |
| # Parse log and build data | |
| # ======================== | |
| $events = @() | |
| Get-Content -LiteralPath $logFile.FullName | | |
| Where-Object { $_ -like '*log_component="Firewall Authentication"*' } | | |
| ForEach-Object { | |
| $line = $_ | |
| # Extract fields using regex | |
| $timestamp = [regex]::Match($line, 'timestamp="([^"]+)"').Groups[1].Value | |
| $logComponent = [regex]::Match($line, 'log_component="([^"]+)"').Groups[1].Value | |
| $severity = [regex]::Match($line, 'severity="([^"]+)"').Groups[1].Value | |
| $message = [regex]::Match($line, 'message="([^"]+)"').Groups[1].Value | |
| $userName = [regex]::Match($line, 'user_name="([^"]+)"').Groups[1].Value | |
| $srcIp = [regex]::Match($line, 'src_ip="([^"]+)"').Groups[1].Value | |
| $status = [regex]::Match($line, 'status="([^"]+)"').Groups[1].Value | |
| if (-not $timestamp) { return } | |
| # Convert ISO timestamp with offset to local time, then format like 13/11/2025 0:45 | |
| $dt = [datetimeoffset]::Parse($timestamp).ToLocalTime() | |
| $timeFormatted = $dt.ToString('dd/MM/yyyy H:mm') | |
| $events += [PSCustomObject]@{ | |
| 'Time' = $timeFormatted | |
| 'Event Type' = $logComponent | |
| 'Severity' = $severity | |
| 'Message' = $message | |
| 'User Name' = $userName | |
| 'Source' = $srcIp | |
| 'Status' = $status | |
| } | |
| } | |
| if (-not $events.Count) { | |
| Write-Warning "No Firewall Authentication events found in $($logFile.FullName)." | |
| } | |
| # ======================== | |
| # Output CSV | |
| # ======================== | |
| if (-not (Test-Path $outputPath)) { | |
| New-Item -ItemType Directory -Path $outputPath -Force | Out-Null | |
| } | |
| $outFileName = "FirewallAuthentication-$($reportDate.ToString('yyyy-MM-dd')).csv" | |
| $outFilePath = Join-Path $outputPath $outFileName | |
| $events | Export-Csv -Path $outFilePath -NoTypeInformation -Encoding UTF8 | |
| Write-Host "Exported $($events.Count) events to $outFilePath" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sophos Firewall Authentication Export Script
This is a PowerShell script that extracts Firewall Authentication events from Sophos XG log files collected by Fastvue Syslog. Below is information on how to use edit and run the script, and how to schedule it to run automatically each day using Windows Task Scheduler.
Overview
The script:
10.1.2.3-2025-11-19.log)log_component="Firewall Authentication"dd/MM/yyyy H:mm(local time)log_component(e.g.Firewall Authentication)Information,Notice)user_name)src_ip)status, e.g.Successful)Example output row:
Script Location and Configuration
Assumed script path (adjust as needed):
At the top of the script you’ll find the configurable variables:
Edit:
$logPathto point to the folder that contains your Sophos XG log files written by Fastvue Syslog. Log files should use the defalt{host}-{date}.logformat.$outputPathto the folder where you want CSV reports to be written.$reportDateif you want to generate a report for a specific date.Running the Script Manually
Copy the above script into a new text file and save it as extract-sophos-auth-events.ps1. We'll assume you've saved it into C:\scripts\extract-sophos-auth-events.ps1.
Open Windows PowerShell as Administrator.
Run:
Check the output folder (e.g.
C:\Firewall Authentication Reports) for a CSV named:Scheduling the Script with Windows Task Scheduler (12:05 AM Daily)
These steps create a scheduled task that runs the script each night at 12:05 AM, exporting authentication events for yesterday.
1. Open Task Scheduler
2. Create a New Task
Export Sophos Firewall AuthenticationExports yesterday's Sophos firewall authentication events to CSV.Administrator).3. Configure the Trigger (12:05 AM Daily)
On a scheduleDaily12:05:00 AM.1days.4. Configure the Action (Run PowerShell Script)
Go to the Actions tab and click New….
Set:
Action:
Start a programProgram/script:
Add arguments (optional):
Start in (optional):
(No quotes in the Start in field.)
Click OK.
5. Conditions & Settings (Recommended)
Conditions tab (optional):
Settings tab (recommended):
Click OK to save the task. You may be prompted for the account password.
Testing the Scheduled Task
Troubleshooting
No log file found
Check that:
logPathis correct.*-YYYY-MM-DD.log.No Firewall Authentication events found
Ensure your Sophos XG is generating
Firewall Authenticationlogs and that they are being sent to the Fastvue Syslog server. Open on of the Fastvue Syslog log files and search for 'Firewall Authentication'.Script doesn’t run from Task Scheduler but works manually
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe