{"id":146,"date":"2007-03-20T17:01:08","date_gmt":"2007-03-20T15:01:08","guid":{"rendered":"http:\/\/contoso.se\/blog\/?p=146"},"modified":"2007-03-20T17:01:08","modified_gmt":"2007-03-20T15:01:08","slug":"check-last-modified-for-a-directory","status":"publish","type":"post","link":"http:\/\/contoso.se\/blog\/?p=146","title":{"rendered":"Check last modified for a directory"},"content":{"rendered":"<p>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.<\/p>\n<p><code>strComputer = \".\"<br \/>\nConst EVENT_WARNING = 2<br \/>\nSet objWMIService = GetObject(\"winmgmts:\" _<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 & \"{impersonationLevel=impersonate}!\\\\\" & strComputer & \"\\root\\cimv2\")<\/code><code>Set colFileList = objWMIService.ExecQuery _<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 (\"ASSOCIATORS OF {Win32_Directory.Name='C:\\'} Where \" _<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 & \"ResultClass = CIM_DataFile\")<\/p>\n<p>For Each objFile In colFileList<br \/>\n\u00c2\u00a0\u00c2\u00a0 \u00c2\u00a0Set objFSO = CreateObject(\"Scripting.FileSystemObject\")<br \/>\n\u00c2\u00a0Set objFile = objFSO.GetFile(objFile.Name)<br \/>\n\u00c2\u00a0<br \/>\n\u00c2\u00a0Set objShell = CreateObject(\"Wscript.Shell\")<br \/>\n\u00c2\u00a0If DateDiff(\"m\", objFile.DateLastModified, Now) > 2 Then<br \/>\n\u00c2\u00a0objShell.LogEvent EVENT_WARNING, _<br \/>\n\u00c2\u00a0\"objFile is older than 2 months. Please investigate. The file is: \" & objFile<br \/>\n\u00c2\u00a0end If<br \/>\nNext<\/p>\n<p>For more settings, please see <a href=\"http:\/\/contoso.se\/blog\/?p=41\">this<\/a> post.<\/p>\n<p><\/code>For more settings, please see post.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 = &#8220;.&#8221; Const EVENT_WARNING = 2 Set objWMIService = GetObject(&#8220;winmgmts:&#8221; _ \u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 &#038; &#8220;{impersonationLevel=impersonate}!\\\\&#8221; &#038; strComputer &#038; &#8220;\\root\\cimv2&#8221;)Set colFileList = objWMIService.ExecQuery _ \u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 (&#8220;ASSOCIATORS &hellip; <a href=\"http:\/\/contoso.se\/blog\/?p=146\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[2,13],"tags":[],"_links":{"self":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/146"}],"collection":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=146"}],"version-history":[{"count":0,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/146\/revisions"}],"wp:attachment":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=146"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}