How-to monitor file size

This script can be used with a monitor to monitor size of a file. In this example it monitor file C:\temp\myfile.txt and will generate an alert if that file is bigger then 50Mb (52428800 bytes). Settings for your two state script monitor can be

  • General
    • Name: Contoso – check file monitor
    • Monitor Target: choose a suitable class
    • Management Pack: choose a suitable MP
  • Schedule
    • Run every 15 Minutes
  • Script
    • File Name: contosocheckfilesize.vbs
    • Script: see below
  • Unhealthy Expression
    • Property[@Name=’Status’] does not contain Ok
  • Healthy Expression
    • Property[@Name=’Status’] contain Ok
  • Health
    • Healthy Healthy Healthy
    • Unhealthy Unhealthy Warning
  • Alerting
    • check Generate alerts fort this monitor
    • check Automatically resolve the alert when the monitor returns to a healthy state
    • Alert Name: Contoso – File Size monitor
    • Alert Description: Warning. C:\temp\myfile.txt is to big. The file is $Data/Context/Property[@Name=’Size’]$ bytes.

Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objFile = objFSO.GetFile(“C:\temp\myfile.txt”)
varSize = objFile.Size

Dim oAPI, oBag
If varSize > 52428800 Then
Set oAPI = CreateObject(“MOM.ScriptAPI”)
Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue(“Status”,”Bad”)
Call oBag.AddValue(“Size”, varSize)
Call oAPI.Return(oBag)
Set oAPI = CreateObject(“MOM.ScriptAPI”)
Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue(“Status”,”Ok”)
Call oAPI.Return(oBag)
End If

10 thoughts on “How-to monitor file size

  1. There is a monitor that can look at “difference” than last time, then you can submit the folder size to SCOM as performance data. If you dont get that to Work you can use a script in a rule. You just have to store the previous folder size somewhere, so you have a value to compare with. You can store that in a temp file.

  2. Is there a way to monitor for file size growth? I need to monitor a file and if that file grows more then 1 mb in 5 minutes to create an alert.

  3. Hi

    Nice and useful script, is there any easy way to monitor folders/files for changes?


  4. Hello,

    I tried the script, if I use c:\\, it will verify the size of the file on the SCOM server. In order to verify on a specific server I changed to (UNC path) ‘\\\C$\\. Which means, if I want to check the size of a specific file on more than one server, I need to add different monitors. Is this correct?

    Thank you,

  5. If you copied and pasted the above script then do a sanity check to ensure that the quote characters are syntactically legal (ie “text” instead of “test” )

  6. Hi

    I wrote the monitor as outlined here. The execution of the script ends in error. In the Alerts view , Alert is Workflow Runtime: Failed to run a process or script ,

    Alert Decsription : The process started at 12:50:10 failed to create System.PropertyBagData. Errors found in output:

    C:\Program Files\System Center Operations Manager 2007\Health Service State\Monitoring Host Temporary Files 1\1711\MyScript.vbs(1, 27) Microsoft VBScript compilation error: Invalid character

    Command executed: “C:\WINNT\system32\cscript.exe” /nologo “MyScript.vbs”
    Working Directory: C:\Program Files\System Center Operations Manager 2007\Health Service State\Monitoring Host Temporary Files 1\1711\

    One or more workflows were affected by this.

    Workflow name: UIGeneratedMonitorf53b56583c8f4d5da57d0f533a4128ec

    Instance name:

    It ends in Compilation error, Invalid Character. I ran it locally on the RMS, it gives the same erro

    Any thoughts



Leave a Reply

Your email address will not be published. Required fields are marked *