# Get-EventLog shows wrong maximum size of event logs

If Get-EventLog and older WMI queries show misleading maximum log size values, Get-WinEvent can return the event log metadata more accurately.

blog

27 Mar 2018 en

[View images (3)](#pf-content-image-1-0)

While working on an event-management script, I noticed that **Get-EventLog** was not returning the correct value for **Maximum File Size**. In the Event Log properties window, the configured maximum size was clearly **2 TB**.

[!\[Event log properties showing the correct maximum log size of 2 TB\](/wp-content/uploads/2018/03/img_5ab9f110cb50c.png)](/wp-content/uploads/2018/03/img_5ab9f110cb50c.png)

But the methods I was testing in PowerShell were showing something completely different.

[!\[PowerShell test output showing incorrect maximum event log size values returned by Get-EventLog\](/wp-content/uploads/2018/03/img_5ab9ec7cf33ae.png)](/wp-content/uploads/2018/03/img_5ab9ec7cf33ae.png)

```powershell
cls

$Computers = Get-ADDomainController -Filter *
$logs = Get-WmiObject Win32_NTEventlogfile -ComputerName $Computers
$logsOutput = $logs | Select
@{Name = "Computername"; Expression = {$_.CSName}},
LogFileName,
FileSize,
NumberOfRecords, @{Name = "MaxMB"; Expression = {$_.MaxFileSize / 1MB}},
@{Name = "PercentUsed"; Expression = { ($_.filesize / $_.maxfilesize) * 100 -as [int]}},
@{Name = "Created"; Expression = {$_.ConvertToDateTime($_.CreationDate)}},
@{Name = "Modified"; Expression = {$_.ConvertToDateTime($_.Lastmodified)}}
$results2 = $logsOutput | Select-Object * | Where-Object { $_.LogFileName -eq "Security" }
$results1 = Get-EventLog -List -ComputerName $computers | Select-Object MachineName, MaximumKilobytes, LogDisplayName, OverflowAction | Where-Object { $_.LogDisplayName -eq "Security" }

Write-Host "WMI TEST"
$results2 | Format-Table -AutoSize
Write-Host "Get-EventLog TEST"
$results1 | Format-Table -AutoSize
```

The important part here is that the **Maximum Log File Size** reported by **Get-EventLog** or the older **WMI** method did not match what the log was actually configured to use.

## Better approach

The better option turned out to be **Get-WinEvent**, which exposes the log metadata more accurately for this scenario.

```powershell
$results = @()
foreach ($computer in $computers) {
    $results += Get-WinEvent -ListLog Security -ComputerName $computer | Select MaximumSizeInBytes, FileSize, IsLogFul, LastAccessTime, LastWriteTime, OldestRecordNumber, RecordCount, LogName, LogType, LogIsolation, IsEnabled, LogMode
}

Write-Host "Get-WinEvent TEST"
$results | ft -AutoSize
```

The results were much better and showed the proper **2 TB** value in `MaximumSizeInBytes`.

[!\[Improved PowerShell results showing the correct 2 TB MaximumSizeInBytes value for the event log\](/wp-content/uploads/2018/03/img_5ab9efb05fa9f.png)](/wp-content/uploads/2018/03/img_5ab9efb05fa9f.png)

## Practical takeaway

If you are reporting on event log configuration and the exact maximum size matters, do not assume `Get-EventLog` is the best source just because it is familiar. For richer metadata, especially when dealing with modern eventing APIs, `Get-WinEvent -ListLog` is often the better choice.

## Related Projects

Projects that align with this post's tags, categories, and content.

[All projects](/projects/)

Matching projects...

[Back to Blog](/blog)

## Related posts

- [PowerShell – Everything you wanted to know about Event Logs and then some](/blog/powershell-everything-you-wanted-to-know-about-event-logs/)
- [Active Directory – How to track down why and where the user account was locked out](/blog/active-directory-how-to-track-down-why-and-where-the-user-account-was-locked-out/)
- [Working with Windows Events with PowerShell](/blog/working-with-windows-events-with-powershell/)

<!-- PowerForge markdown artifact sha256:1DE6E83F17DE39300FEFF90062CFC92FB2C2ACC4494CD897A75C805A308BF671 -->
