trigger an alarm if there are too many files in a folder

atera01
atera01 Member Posts: 3

Hello,

we have a folder on a Windows file server into which files are constantly being added, which are then automatically processed and deleted by a process.

If an error occurs, more and more files accumulate in this folder, then we would like to have an alarm that says there are too many files in the folder (for example, more than 10). How can I implement this with PowerShell?

Tagged:

Comments

  • anton
    anton Member Posts: 13
    edited October 2

    Heres one way. Maybe theres a better way.

    1. Create a script that counts files & folders of a specified directory
    # Specify the path to the folder
    $folderPath = "C:\path\to\folder"
    # Count the number of files and folders combined
    $itemCount = (Get-ChildItem -Path $folderPath).Count
    # Output the result
    Write-Host "$itemCount"
    

    2. Create a Threshold, that monitors the number.

    3. Apply threshold to devices

    Hope this helps, good luck 😁

  • atera01
    atera01 Member Posts: 3

    Thank you, it works, but there is always only 1 alarm e-mail, even if another file is added in a short time.

  • anton
    anton Member Posts: 13

    You can duplicate the threshold and have another value set at 20.

    example.

    informational status at 10, warning at 20, critical at 30.