How do I limit the size of Sysmon folder content?

ADRookie 0 Reputation points
2024-01-15T07:42:51.38+00:00

We have sysmon configured in our servers C:\Sysmon. There is no quota or limit on this folder set, so it keep inclreasing and we get the high disk volume alerts in odd hours, then we have to delete the files manually. Is there any option to capping the size of this folder?

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
13,236 questions
Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,652 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Azar 22,870 Reputation points MVP
    2024-01-15T08:30:32.94+00:00

    Hey ADRookie

    To cap the size of your Sysmon folder and avoid those pesky disk volume alerts, you can use a combination of built-in Windows tools and a scheduled task.

    Firstly create a PowerShell script (eg- CapSysmonSize.ps1)

    $sysmonPath = "C:\Sysmon" $maxSizeGB = 10  # Set your desired maximum size in gigabytes  $sysmonSizeGB = (Get-ChildItem -Path $sysmonPath -Recurse | Measure-Object -Property Length -Sum).Sum / 1GB  if ($sysmonSizeGB -gt $maxSizeGB) {     Get-ChildItem -Path $sysmonPath -Recurse | Sort-Object LastWriteTime | Select-Object -First 1 | Remove-Item -Force } 
    

    Then open Task Scheduler on your server and Create a new task, and in the Actions tab, set the action to "Start a program.

    Point it to powershell.exe with arguments

    -NoProfile -ExecutionPolicy Bypass -File "C:\Path\To\CapSysmonSize.ps1"
    

    Finally Configure the trigger based on your desired schedule (e.g., daily, weekly).

    This script checks the size of your Sysmon folder and, if it exceeds the specified limit, removes the oldest file until it's within the size limit. Adjust the script and scheduled task parameters based on your needs. If this helps kindly accept the answer thanks much.


  2. Ian Xue 37,706 Reputation points Microsoft Vendor
    2024-01-16T05:41:20.2066667+00:00

    Hi,

    To limit the folder size, you can add the role File Server Resource Manager to your server and create a quota on the folder.

    Please refer to this link for more details https://learn.microsoft.com/en-us/windows-server/storage/fsrm/quota-management

    Best Regards,

    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.


  3. Justin Herman 5 Reputation points
    2024-07-30T16:35:06.15+00:00

    @ADRookie I created a simple script and created it to run monthly using the SYSTEM account. This script will keep a years worth of deleted files. We agreed to that timeframe for investigative / historical purposes.

    Get-ChildItem -Path C:\Sysmon -Recurse | Where-Object {$_.LastAccessTime -lt (Get-Date).AddDays(-365)} | Remove-Item -Force

    You can delete the middle "Where-Object" portion to completely empty the folder. I suggest keeping some recent files in there and change the (-365) to (-30) to keep at least a months worth of files.

    I also used the LastAccessTime in lieu of LastModifiedTime or any other date because that is the closest representation of the when the file was deleted and placed into the Sysmon folder. An old file modified years ago, but deleted yesterday would be removed as soon as the script runs if LastModifiedDate is used. It really depends on your intent and goal here.

    Save the above script into a ps1 file, store locally on the system, create scheduled task using the SYSTEM account, and configure the rest however you wish. For Action, we use Run powershell.exe and Add arguments "-File C:\powershell\SysmonCleanup.ps1" (but can be any location you store the ps1).

    I am working on a PowerShell script to create the scheduled task since we have over 1,000 Windows devices to run this on.

    Justin

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.