Home » Microsoft Operations Manager 2005 » Check last modified for a directory

Check last modified for a directory

I have done a simple script to check last modified on all files in a directory. This example will generate a local event if files are older then 2 months.

strComputer = "."
Const EVENT_WARNING = 2
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFileList = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='C:\'} Where " _
        & "ResultClass = CIM_DataFile")

For Each objFile In colFileList
    Set objFSO = CreateObject("Scripting.FileSystemObject")
 Set objFile = objFSO.GetFile(objFile.Name)
 
 Set objShell = CreateObject("Wscript.Shell")
 If DateDiff("m", objFile.DateLastModified, Now) > 2 Then
 objShell.LogEvent EVENT_WARNING, _
 "objFile is older than 2 months. Please investigate. The file is: " & objFile
 end If
Next

For more settings, please see this post.

For more settings, please see post.