# Get-EventLog shows wrong maximum size of event logs

While working on EventManager script I’ve noticed that Get-EventLog is not returning proper values for Maximum File Size. When checking Maximum log…

blog

27 Mar 2018 pl

[Zobacz obrazy (3)](#pf-content-image-1-0)

While working on EventManager script I've noticed that Get-EventLog is not returning proper values for **Maximum File Size.** When checking Maximum log size directly it was showing 2TB.

[!\[Wlasciwosci dziennika zdarzen pokazujace poprawny maksymalny rozmiar logu 2 TB\](/wp-content/uploads/2018/03/img_5ab9f110cb50c.png)](/wp-content/uploads/2018/03/img_5ab9f110cb50c.png)

But the test methods I used where showing different values.

[!\[Wynik testu PowerShell pokazujacy niepoprawne wartosci maksymalnego rozmiaru dziennika zwracane przez Get-EventLog\](/wp-content/uploads/2018/03/img_5ab9ec7cf33ae.png)](/wp-content/uploads/2018/03/img_5ab9ec7cf33ae.png)

```plain
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 **Maximum Log File Size **reported by **Get-EventLog** or **WMI** method is not reporting correct values

### 💡 Solution

Fortunately there is a way to get proper values. With help of Johan Åkerström who suggested **Get-WinEven**t I was able to get values I was running for.

```plain
$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 are much better showing proper 2TB **MaximumSizeInBytes**

[!\[Poprawiony wynik PowerShell pokazujacy prawidlowa wartosc MaximumSizeInBytes rowna 2 TB dla dziennika zdarzen\](/wp-content/uploads/2018/03/img_5ab9efb05fa9f.png)](/wp-content/uploads/2018/03/img_5ab9efb05fa9f.png)

## Powiązane projekty

Projekty powiązane z tagami, kategoriami i treścią tego wpisu.

[Wszystkie projekty](/projekty/)

Trwa dopasowywanie projektów...

[Powrót do bloga](/blog/)

## Powiązane wpisy

- [Check an API write after a PowerShell timeout](/blog/verify-uncertain-api-outcomes-powershell/)
- [Inspect and convert mixed Office archives with PSWriteOffice](/blog/inspect-and-convert-mixed-office-archives-pswriteoffice/)
- [Compose PDF reports and automate page workflows with PSWriteOffice](/blog/automate-pdf-reports-and-page-workflows-pswriteoffice/)

<!-- PowerForge markdown artifact sha256:A766640EE235DF7AE049FF3F437E386666747C8BEC6CDEF2AB55CC03FAA6DE95 -->
