Hi All,
Welcome back, today we will discussing on How to change Event Log File Size using Powershell. First let me tell you how I got the idea of writing this post.
Recently I came across issues reporting that the users are not able to log into the machines and they were receiving errors stating that the Security logs are full and to contact the system Admin for the same.
So let us jump right in and see what we have to explore.
Power up the Event Viewer to see the security logs and the size allocated. To do so, go to Windows Logs, Right click on Security and click on Properties.
The below pops up showing us that the current value of the log size is set to 24960KB (approximately 25MB).
I can check the same through Powershell using below.
At first, let us see all logs using Get-WMIObject
Get-WMIObject Win32_NTEventLogFile
In the next step we will select only the security logs and check the Max Log File Size as we saw through the GUI.
$SecurityLogs = Get-WmiObject Win32_NTEventLogFile | where {$_.LogFileName -like "Security"}
$SecurityLogs.MaxFileSize
The value is seen is in Bytes. So we get the same result as expected.
Now say that I want to change that value to 30MB.
$SecurityLogs.MaxFileSize = 30MB
As you just saw it was very easy to change the value.
This is just one way of doing this. We also another method which would seem easier.
Limit-EventLog -LogName Security -MaximumSize 30MB
As you can see the cmdlet Limit-EventLog accepts ComputerName parameter, so it is very easy to change the values on a lot of computers at one go.
$Servers = Get-Content C:\Serverlist.txt
Foreach($Server in $Servers){
Limit-EventLog -LogName System -MaximumSize 50MB -ComputerName $Server
}
In the above example, we are setting the System Event Log File Size to 50MB.
That's it for today, I hope this has been informative and thank you for reading!