Microsoft Windows – listing and exporting (“reading out”) all event logs using the modern ‚Get-WinEvent‘ cmdlet which can retrieve all logs available on the system and output their contents to an external file

————————————————————————————————————————
# Define the directory where logs will be unloaded
$exportPath = „C:\Logs“
# Create the folder if it does not exist
if (-not (Test-Path $exportPath)) {
New-Item -ItemType Directory -Path $exportPath | Out-Null
}
# Fetch all logs that actually contain events to avoid empty files
$allLogs = Get-WinEvent -ListLog * | Where-Object { $_.RecordCount -gt 0 }
foreach ($log in $allLogs) {
Write-Host „Unloading log: $($log.LogName)…“ -ForegroundColor Cyan
try {
# Sanitize the log name to make it a safe file name
$safeName = $log.LogName -replace ‚[\\/:\*\?“<>\|]‘, ‚_‘
$outputFile = Join-Path $exportPath „$safeName.csv“
# Pull events and export them
Get-WinEvent -LogName $log.LogName -ErrorAction SilentlyContinue |
Select-Object TimeCreated, Id, LevelDisplayName, Source, Message |
Export-Csv -Path $outputFile -NoTypeInformation -Encoding UTF8
}
catch {
Write-Warning „Failed to unload log: $($log.LogName). Requires higher privileges or log is locked.“
}
}
Write-Host „All event logs have been successfully unloaded to $exportPath“ -ForegroundColor Green
————————————————————————————————————————
PS C:\Logs> C:\Logs\EventLogs.ps1
Unloading log: Windows PowerShell…
Unloading log: System…
Unloading log: Security…
Unloading log: Application…
Unloading log: Setup…
Unloading log: OpenSSH/Operational…
Unloading log: OpenSSH/Admin…
Unloading log: Microsoft-Windows-WMI-Activity/Operational…
Unloading log: Microsoft-Windows-WinRM/Operational…
Unloading log: Microsoft-Windows-Winlogon/Operational…
Unloading log: Microsoft-Windows-WinINet-Config/ProxyConfigChanged…
Unloading log: Microsoft-Windows-WindowsUpdateClient/Operational…
Unloading log: Microsoft-Windows-WindowsSystemAssessmentTool/Operational…
Unloading log: Microsoft-Windows-Windows Firewall With Advanced Security/FirewallDiagnostics…
Unloading log: Microsoft-Windows-Windows Firewall With Advanced Security/Firewall…
Unloading log: Microsoft-Windows-Windows Defender/Operational…
Unloading log: Microsoft-Windows-WFP/Operational…
Unloading log: Microsoft-Windows-WER-PayloadHealth/Operational…
Unloading log: Microsoft-Windows-WebAuthN/Operational…
Unloading log: Microsoft-Windows-Wcmsvc/Operational…
Unloading log: Microsoft-Windows-VolumeSnapshot-Driver/Operational…
Unloading log: Microsoft-Windows-UserSettingsBackup-Orchestrator/Operational…
Unloading log: Microsoft-Windows-UserPnp/DeviceInstall…
Unloading log: Microsoft-Windows-User Profile Service/Operational…
Unloading log: Microsoft-Windows-User Device Registration/Admin…
Unloading log: Microsoft-Windows-UniversalTelemetryClient/Operational…
Unloading log: Microsoft-Windows-TZSync/Operational…
Unloading log: Microsoft-Windows-TWinUI/Operational…
Unloading log: Microsoft-Windows-Time-Service/Operational…
Unloading log: Microsoft-Windows-TerminalServices-ServerUSBDevices/Admin…
Unloading log: Microsoft-Windows-TerminalServices-RemoteConnectionManager/Operational…
Unloading log: Microsoft-Windows-TerminalServices-RemoteConnectionManager/Admin…
Unloading log: Microsoft-Windows-TerminalServices-PnPDevices/Admin…
Unloading log: Microsoft-Windows-TerminalServices-LocalSessionManager/Operational…
Unloading log: Microsoft-Windows-TaskScheduler/Maintenance…
Unloading log: Microsoft-Windows-Storsvc/Diagnostic…
Unloading log: Microsoft-Windows-Store/Operational…
Unloading log: Microsoft-Windows-StorageVolume/Operational…
Unloading log: Microsoft-Windows-StorageSpaces-Driver/Operational…
Unloading log: Microsoft-Windows-StorageManagement/Operational…
Unloading log: Microsoft-Windows-Storage-Storport/Operational…
Unloading log: Microsoft-Windows-Storage-Storport/Health…
Unloading log: Microsoft-Windows-StateRepository/Operational…
Unloading log: Microsoft-Windows-SMBServer/Operational…
Unloading log: Microsoft-Windows-SMBServer/Connectivity…
Unloading log: Microsoft-Windows-SMBClient/Operational…
Unloading log: Microsoft-Windows-SmbClient/Connectivity…
Unloading log: Microsoft-Windows-SmartCard-DeviceEnum/Operational…
Unloading log: Microsoft-Windows-ShellCommon-StartLayoutPopulation/Operational…
Unloading log: Microsoft-Windows-Shell-Core/Operational…
Unloading log: Microsoft-Windows-Shell-Core/AppDefaults…
Unloading log: Microsoft-Windows-Security-SPP-UX-Notifications/ActionCenter…
Unloading log: Microsoft-Windows-Security-Mitigations/KernelMode…
Unloading log: Microsoft-Windows-Security-LessPrivilegedAppContainer/Operational…
Unloading log: Microsoft-Windows-Resource-Exhaustion-Resolver/Operational…
Unloading log: Microsoft-Windows-Resource-Exhaustion-Detector/Operational…
Unloading log: Microsoft-Windows-RemoteDesktopServices-RdpCoreTS/Operational…
Unloading log: Microsoft-Windows-ReadyBoost/Operational…
Unloading log: Microsoft-Windows-PushNotification-Platform/Operational…
Unloading log: Microsoft-Windows-Provisioning-Diagnostics-Provider/Admin…
Unloading log: Microsoft-Windows-Privacy-Auditing/Operational…
Unloading log: Microsoft-Windows-PrintService/Admin…
Unloading log: Microsoft-Windows-PowerShell/Operational…
Unloading log: Microsoft-Windows-Perflib/Operational…
Unloading log: Microsoft-Windows-PCRPF/PCRPF…
Unloading log: Microsoft-Windows-PCI/Operational…
Unloading log: Microsoft-Windows-Partition/Diagnostic…
Unloading log: Microsoft-Windows-NTLM/Operational…
Unloading log: Microsoft-Windows-Ntfs/WHC…
Unloading log: Microsoft-Windows-Ntfs/Operational…
Unloading log: Microsoft-Windows-NlaSvc/Operational…
Unloading log: Microsoft-Windows-NetworkProfile/Operational…
Unloading log: Microsoft-Windows-NCSI/Operational…
Unloading log: Microsoft-Windows-MUI/Operational…
Unloading log: Microsoft-Windows-ModernDeployment-Diagnostics-Provider/ManagementService…
Unloading log: Microsoft-Windows-ModernDeployment-Diagnostics-Provider/Autopilot…
Unloading log: Microsoft-Windows-MF-FrameServer/Camera_FrameServer…
Unloading log: Microsoft-Windows-LiveId/Operational…
Unloading log: Microsoft-Windows-LanguagePackSetup/Operational…
Unloading log: Microsoft-Windows-Known Folders API Service…
Unloading log: Microsoft-Windows-Kernel-WHEA/Operational…
Unloading log: Microsoft-Windows-Kernel-ShimEngine/Operational…
Unloading log: Microsoft-Windows-Kernel-PnP/Device Management…
Unloading log: Microsoft-Windows-Kernel-PnP/Configuration…
Unloading log: Microsoft-Windows-Kernel-EventTracing/Admin…
Unloading log: Microsoft-Windows-Kernel-Dump/Operational…
Unloading log: Microsoft-Windows-Kernel-Cache/Operational…
Unloading log: Microsoft-Windows-Kernel-Boot/Operational…
Unloading log: Microsoft-Windows-HelloForBusiness/Operational…
Unloading log: Microsoft-Windows-GroupPolicy/Operational…
Unloading log: Microsoft-Windows-Diagnostics-Performance/Operational…
Unloading log: Microsoft-Windows-Diagnosis-Scripted/Operational…
Unloading log: Microsoft-Windows-Diagnosis-Scripted/Admin…
Unloading log: Microsoft-Windows-Diagnosis-Scheduled/Operational…
Unloading log: Microsoft-Windows-Diagnosis-PCW/Operational…
Unloading log: Microsoft-Windows-Diagnosis-DPS/Operational…
Unloading log: Microsoft-Windows-Dhcp-Client/Admin…
Unloading log: Microsoft-Windows-DeviceSetupManager/Operational…
Unloading log: Microsoft-Windows-DeviceSetupManager/Admin…
Unloading log: Microsoft-Windows-DeviceManagement-Enterprise-Diagnostics-Provider/Operational…
Unloading log: Microsoft-Windows-DeviceManagement-Enterprise-Diagnostics-Provider/Admin…
Unloading log: Microsoft-Windows-Crypto-NCrypt/Operational…
Unloading log: Microsoft-Windows-Crypto-NCrypt/KeyMgmt…
Unloading log: Microsoft-Windows-Crypto-DPAPI/Operational…
Unloading log: Microsoft-Windows-Containers-Wcifs/Operational…
Unloading log: Microsoft-Windows-Containers-BindFlt/Operational…
Unloading log: Microsoft-Windows-CodeIntegrity/Operational…
Unloading log: Microsoft-Windows-CloudStore/Operational…
Unloading log: Microsoft-Windows-CloudStore/Initialization…
Unloading log: Microsoft-Windows-CloudRestoreLauncher/Operational…
Unloading log: Microsoft-Windows-CloudFiles-Filter/Operational…
Unloading log: Microsoft-Windows-Bits-Client/Operational…
Unloading log: Microsoft-Windows-BitLocker/BitLocker Management…
Unloading log: Microsoft-Windows-Biometrics/Operational…
Unloading log: Microsoft-Windows-BackgroundTaskInfrastructure/Operational…
Unloading log: Microsoft-Windows-Authentication User Interface/Operational…
Unloading log: Microsoft-Windows-Audio/PlaybackManager…
Unloading log: Microsoft-Windows-Audio/Operational…
Unloading log: Microsoft-Windows-AppxPackaging/Operational…
Unloading log: Microsoft-Windows-AppXDeploymentServer/Restricted…
Unloading log: Microsoft-Windows-AppXDeploymentServer/Operational…
Unloading log: Microsoft-Windows-AppXDeployment/Operational…
Unloading log: Microsoft-Windows-AppXDeployment-Server/Operational…
Unloading log: Microsoft-Windows-AppReadiness/Operational…
Unloading log: Microsoft-Windows-AppReadiness/Admin…
Unloading log: Microsoft-Windows-AppModel-Runtime/Admin…
Unloading log: Microsoft-Windows-AppLocker/EXE and DLL…
Unloading log: Microsoft-Windows-Application-Experience/Program-Telemetry…
Unloading log: Microsoft-Windows-Application-Experience/Program-Compatibility-Assistant…
Unloading log: Microsoft-Windows-AppID/Operational…
Unloading log: Microsoft-Windows-AAD/Operational…
Unloading log: Microsoft-Client-Licensing-Platform/Admin…
All event logs have been successfully unloaded to C:\Logs
PS C:\Logs>
————————————————————————————————————————
# Clear all logs that have recorded entries
$logs = Get-WinEvent -ListLog * | Where-Object { $_.RecordCount -gt 0 }
foreach ($log in $logs) {
Write-Host „Clearing log: $($log.LogName)“ -ForegroundColor Yellow
try {
# Use the .NET EventLogSession class to safely clear the log
[System.Diagnostics.Eventing.Reader.EventLogSession]::GlobalSession.ClearLog($log.LogName)
}
catch {
Write-Warning „Could not clear log: $($log.LogName)“
}
}
————————————————————————————————————————
PS C:\Logs> C:\Logs\EventLogsDelete.ps1
Clearing log: Windows PowerShell
Clearing log: System
Clearing log: Security
Clearing log: Application
Clearing log: Setup
Clearing log: OpenSSH/Operational
Clearing log: OpenSSH/Admin
Clearing log: Microsoft-Windows-WMI-Activity/Operational
Clearing log: Microsoft-Windows-WinRM/Operational
Clearing log: Microsoft-Windows-Winlogon/Operational
Clearing log: Microsoft-Windows-WinINet-Config/ProxyConfigChanged
Clearing log: Microsoft-Windows-WindowsUpdateClient/Operational
Clearing log: Microsoft-Windows-WindowsSystemAssessmentTool/Operational
Clearing log: Microsoft-Windows-Windows Firewall With Advanced Security/FirewallDiagnostics
Clearing log: Microsoft-Windows-Windows Firewall With Advanced Security/Firewall
Clearing log: Microsoft-Windows-Windows Defender/Operational
Clearing log: Microsoft-Windows-WFP/Operational
Clearing log: Microsoft-Windows-WER-PayloadHealth/Operational
Clearing log: Microsoft-Windows-WebAuthN/Operational
Clearing log: Microsoft-Windows-Wcmsvc/Operational
Clearing log: Microsoft-Windows-VolumeSnapshot-Driver/Operational
Clearing log: Microsoft-Windows-UserSettingsBackup-Orchestrator/Operational
Clearing log: Microsoft-Windows-UserPnp/DeviceInstall
Clearing log: Microsoft-Windows-User Profile Service/Operational
Clearing log: Microsoft-Windows-User Device Registration/Admin
Clearing log: Microsoft-Windows-UniversalTelemetryClient/Operational
Clearing log: Microsoft-Windows-TZSync/Operational
Clearing log: Microsoft-Windows-TWinUI/Operational
Clearing log: Microsoft-Windows-Time-Service/Operational
Clearing log: Microsoft-Windows-TerminalServices-ServerUSBDevices/Admin
Clearing log: Microsoft-Windows-TerminalServices-RemoteConnectionManager/Operational
Clearing log: Microsoft-Windows-TerminalServices-RemoteConnectionManager/Admin
Clearing log: Microsoft-Windows-TerminalServices-PnPDevices/Admin
Clearing log: Microsoft-Windows-TerminalServices-LocalSessionManager/Operational
Clearing log: Microsoft-Windows-TaskScheduler/Maintenance
Clearing log: Microsoft-Windows-Storsvc/Diagnostic
Clearing log: Microsoft-Windows-Store/Operational
Clearing log: Microsoft-Windows-StorageVolume/Operational
Clearing log: Microsoft-Windows-StorageSpaces-Driver/Operational
Clearing log: Microsoft-Windows-StorageManagement/Operational
Clearing log: Microsoft-Windows-Storage-Storport/Operational
Clearing log: Microsoft-Windows-Storage-Storport/Health
Clearing log: Microsoft-Windows-StateRepository/Operational
Clearing log: Microsoft-Windows-SMBServer/Operational
Clearing log: Microsoft-Windows-SMBServer/Connectivity
Clearing log: Microsoft-Windows-SMBClient/Operational
Clearing log: Microsoft-Windows-SmbClient/Connectivity
Clearing log: Microsoft-Windows-SmartCard-DeviceEnum/Operational
Clearing log: Microsoft-Windows-ShellCommon-StartLayoutPopulation/Operational
Clearing log: Microsoft-Windows-Shell-Core/Operational
Clearing log: Microsoft-Windows-Shell-Core/AppDefaults
Clearing log: Microsoft-Windows-Security-SPP-UX-Notifications/ActionCenter
Clearing log: Microsoft-Windows-Security-Mitigations/KernelMode
Clearing log: Microsoft-Windows-Security-LessPrivilegedAppContainer/Operational
Clearing log: Microsoft-Windows-Resource-Exhaustion-Resolver/Operational
Clearing log: Microsoft-Windows-Resource-Exhaustion-Detector/Operational
Clearing log: Microsoft-Windows-RemoteDesktopServices-RdpCoreTS/Operational
Clearing log: Microsoft-Windows-ReadyBoost/Operational
Clearing log: Microsoft-Windows-PushNotification-Platform/Operational
Clearing log: Microsoft-Windows-Provisioning-Diagnostics-Provider/Admin
Clearing log: Microsoft-Windows-Privacy-Auditing/Operational
Clearing log: Microsoft-Windows-PrintService/Admin
Clearing log: Microsoft-Windows-PowerShell/Operational
Clearing log: Microsoft-Windows-Perflib/Operational
Clearing log: Microsoft-Windows-PCRPF/PCRPF
Clearing log: Microsoft-Windows-PCI/Operational
Clearing log: Microsoft-Windows-Partition/Diagnostic
Clearing log: Microsoft-Windows-NTLM/Operational
Clearing log: Microsoft-Windows-Ntfs/WHC
Clearing log: Microsoft-Windows-Ntfs/Operational
Clearing log: Microsoft-Windows-NlaSvc/Operational
Clearing log: Microsoft-Windows-NetworkProfile/Operational
Clearing log: Microsoft-Windows-NCSI/Operational
Clearing log: Microsoft-Windows-MUI/Operational
Clearing log: Microsoft-Windows-ModernDeployment-Diagnostics-Provider/ManagementService
Clearing log: Microsoft-Windows-ModernDeployment-Diagnostics-Provider/Autopilot
Clearing log: Microsoft-Windows-MF-FrameServer/Camera_FrameServer
Clearing log: Microsoft-Windows-LiveId/Operational
WARNUNG: Could not clear log: Microsoft-Windows-LiveId/Operational
Clearing log: Microsoft-Windows-LanguagePackSetup/Operational
Clearing log: Microsoft-Windows-Known Folders API Service
Clearing log: Microsoft-Windows-Kernel-WHEA/Operational
Clearing log: Microsoft-Windows-Kernel-ShimEngine/Operational
Clearing log: Microsoft-Windows-Kernel-PnP/Device Management
Clearing log: Microsoft-Windows-Kernel-PnP/Configuration
Clearing log: Microsoft-Windows-Kernel-EventTracing/Admin
Clearing log: Microsoft-Windows-Kernel-Dump/Operational
Clearing log: Microsoft-Windows-Kernel-Cache/Operational
Clearing log: Microsoft-Windows-Kernel-Boot/Operational
Clearing log: Microsoft-Windows-HelloForBusiness/Operational
Clearing log: Microsoft-Windows-GroupPolicy/Operational
Clearing log: Microsoft-Windows-Diagnostics-Performance/Operational
Clearing log: Microsoft-Windows-Diagnosis-Scripted/Operational
Clearing log: Microsoft-Windows-Diagnosis-Scripted/Admin
Clearing log: Microsoft-Windows-Diagnosis-Scheduled/Operational
Clearing log: Microsoft-Windows-Diagnosis-PCW/Operational
Clearing log: Microsoft-Windows-Diagnosis-DPS/Operational
Clearing log: Microsoft-Windows-Dhcp-Client/Admin
Clearing log: Microsoft-Windows-DeviceSetupManager/Operational
Clearing log: Microsoft-Windows-DeviceSetupManager/Admin
Clearing log: Microsoft-Windows-DeviceManagement-Enterprise-Diagnostics-Provider/Operational
Clearing log: Microsoft-Windows-DeviceManagement-Enterprise-Diagnostics-Provider/Admin
Clearing log: Microsoft-Windows-Crypto-NCrypt/Operational
Clearing log: Microsoft-Windows-Crypto-NCrypt/KeyMgmt
Clearing log: Microsoft-Windows-Crypto-DPAPI/Operational
Clearing log: Microsoft-Windows-Containers-Wcifs/Operational
Clearing log: Microsoft-Windows-Containers-BindFlt/Operational
Clearing log: Microsoft-Windows-CodeIntegrity/Operational
Clearing log: Microsoft-Windows-CloudStore/Operational
Clearing log: Microsoft-Windows-CloudStore/Initialization
Clearing log: Microsoft-Windows-CloudRestoreLauncher/Operational
Clearing log: Microsoft-Windows-CloudFiles-Filter/Operational
Clearing log: Microsoft-Windows-Bits-Client/Operational
Clearing log: Microsoft-Windows-BitLocker/BitLocker Management
Clearing log: Microsoft-Windows-Biometrics/Operational
Clearing log: Microsoft-Windows-BackgroundTaskInfrastructure/Operational
Clearing log: Microsoft-Windows-Authentication User Interface/Operational
Clearing log: Microsoft-Windows-Audio/PlaybackManager
Clearing log: Microsoft-Windows-Audio/Operational
Clearing log: Microsoft-Windows-AppxPackaging/Operational
Clearing log: Microsoft-Windows-AppXDeploymentServer/Restricted
Clearing log: Microsoft-Windows-AppXDeploymentServer/Operational
Clearing log: Microsoft-Windows-AppXDeployment/Operational
Clearing log: Microsoft-Windows-AppXDeployment-Server/Operational
Clearing log: Microsoft-Windows-AppReadiness/Operational
Clearing log: Microsoft-Windows-AppReadiness/Admin
Clearing log: Microsoft-Windows-AppModel-Runtime/Admin
Clearing log: Microsoft-Windows-AppLocker/EXE and DLL
Clearing log: Microsoft-Windows-Application-Experience/Program-Telemetry
Clearing log: Microsoft-Windows-Application-Experience/Program-Compatibility-Assistant
Clearing log: Microsoft-Windows-AppID/Operational
Clearing log: Microsoft-Windows-AAD/Operational
Clearing log: Microsoft-Client-Licensing-Platform/Admin

PS C:\Logs>
————————————————————————————————————————

Leave a Reply

You must be logged in to post a comment.