Home » Scripts » How-to monitor file size

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


  1. Hi Anders,

    I read your blog and I must say its very informative and very near to my requirement. Basically my requirement is like this:-

    1). Monitor the folders size under directory C:\Temp
    2). Whenever the folder size under C:\Temp reaches to 1 TB, then pick/extract first 5 characters from the folder name. Eg Just extract “Folde” from “Folder_Name”
    3). Then search these 5 characters(“Folde”) in another directory lets say D:\Software\Location and extract the matching file name
    4). And then send this file name by email.

    I hope you can help me in this. Please let me if you need more information.
    Thanks in Advance!!!


  2. 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.

  3. 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.

  4. Hi

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


  5. Hi, thanks for reading my blog. That is correct, you will have to use one monitor per file. But you could of course re-write the script to support multiple files.

  6. 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,

  7. 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” )

  8. 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: slgwvm05.internal.standardlife.com

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

    Any thoughts



Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.