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


Welcome to contoso.se! My name is Anders Bengtsson and this is my blog about Azure infrastructure and system management. I am a senior engineer in the FastTrack for Azure team, part of Azure Engineering, at Microsoft.  Contoso.se has two main purposes, first as a platform to share information with the community and the second as a notebook for myself.

Everything you read here is my own personal opinion and any code is provided "AS-IS" with no warranties.

Anders Bengtsson

MVP awarded 2007,2008,2009,2010

My Books
Service Manager Unleashed
Service Manager Unleashed
Orchestrator Unleashed
Orchestrator 2012 Unleashed
Inside the Microsoft Operations Management Suite

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 = "."
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

For more settings, please see this post.

For more settings, please see post.