Powershell – How do -RetentionDays and -MaximumSize parameters work in Limit-EventLog in PowerShell

powershellwindows-server-2012

I want to increase the size of the Windows Application Log using Powershell and intend to use Limit-EventLog. I must keep at least 7 days of logs and have plenty of disk space (at least up to the 4GB limit). My question is if I run a command like this:

Limit-EventLog -LogName "Application" -MaximumSize 4092MB -RetentionDays 7 -OverflowAction "OverwriteOlder"

If there are events in the event log older than 7 days, and there is lots of free space, does Windows keep the oldest records, or does it start overwriting events older than 7 days? If I have reached a 7 days retention period I don't want to grow the log unnecessarily.

I'm unsure how these two parameters work together and the documentation is not explicit enough.

Best Answer

My understanding from setting this using local security policy (GPO) which I'm guessing will be the same behavior is that it will overwrite firstly if it gets to the maximumsize or if the maximumsize is not met it will start to overwrite after 7 days.