Monitor file and directory size

This script will monitor file and directory size. It will generate performance data back to the management server. You can view this information under performance view in Operators Console or/and in reports. This first example will monitor the size C:\pagefile.sys
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("c:\pagefile.sys")
CreatePerfData "File","File Size",objFile.Path,objFile.Size
Sub CreatePerfData(strObjectName,strCounterName,strInstanceName,numValue)
    Set objPerfData = ScriptContext.CreatePerfData
    objPerfData.ObjectName = strObjectName
    objPerfData.CounterName =strCounterName
    objPerfData.InstanceName = strInstanceName
    objPerfData.Value = numValue
    ScriptContext.Submit objPerfData
End Sub

This example will monitor the size of all subfolders under C:\ 

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\")
Set colSubfolders = objFolder.Subfolders
For Each objSubfolder in colSubfolders
CreatePerfData "File","File Size",objSubfolder.Path,objSubfolder.Size
Next
Sub CreatePerfData(strObjectName,strCounterName,strInstanceName,numValue)
                    Set objPerfData = ScriptContext.CreatePerfData
                    objPerfData.ObjectName = strObjectName
                    objPerfData.CounterName =strCounterName
                    objPerfData.InstanceName = strInstanceName
                    objPerfData.Value = numValue
                    ScriptContext.Submit objPerfData
End Sub

  1. Insert the script as a new script in Administrator Console
  2. Create a event rule that run the script every X minute
  3. Commit configuration change and wait until the script has run
  4. Open Operator Console, click performance, click you server and choose your new FILE performance objects, click draw graph

There is a guide about how to create performance data reports at momresources.org

About

Microsoft

One thought on “Monitor file and directory size

Comments are closed.