PowerShell 2.0: One Cmdlet at a Time 66 Limit-EventLog
Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Limit-EventLog cmdlet.
What can I do with it?
Set the size and age properties of an Event Log.
Example:
Set the following properties on the Application Log on the remote computer Test01:
Maximum Size = 5MB
OverflowAction = DoNotOverWrite
Limit-EventLog -ComputerName Test01 -LogName Application -MaximumSize 5MB -OverflowAction DoNotOverWrite
Before:
After:
How could I have done this in PowerShell 1.0?
You could use WMI to set properties on an event log. For example to set the MaxFileSize of the Application Log to 5MB use the below. (Thanks to Richard Siddaway for the tip that you need to use psbase to save the changes, just Put() doesn’t work.)
$EventLog = Get-WmiObject -Class Win32_NTEventLogFile -Filter “LogFileName = ‘Application’” $EventLog.MaxFileSize = 5242880 $EventLog.psbase.Put()