{"id":57,"date":"2006-07-11T21:35:43","date_gmt":"2006-07-11T19:35:43","guid":{"rendered":"http:\/\/contoso.se\/blog\/?p=57"},"modified":"2006-12-28T21:55:59","modified_gmt":"2006-12-28T19:55:59","slug":"rakna-filer","status":"publish","type":"post","link":"http:\/\/contoso.se\/blog\/?p=57","title":{"rendered":"Count Files"},"content":{"rendered":"<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 10pt\"><font face=\"Calibri\" size=\"3\">Here is a script that will count file in a directory. If there is more than X file in the directory a event will be generated in the local event viewer. You can create a event rule that runs the script and a collection rule that collections event ID 2 from your machine. The local event will have event ID 2, you can also add criteria to check if description includes &#8220;There is more than&#8221;. <\/font><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 10pt\"><font face=\"Calibri\" size=\"3\">In the following example the script will monitor if C:\\ have more than 2 files.<\/font><\/p>\n<p><span style=\"font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-size: 11.0pt\">Set fs = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)<\/span><span style=\"font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'\"><br \/>\n<\/span><span style=\"font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-size: 11.0pt\">folderName = &#8220;c:\\&#8221;<\/span><span style=\"font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'\"><br \/>\n<\/span><span style=\"font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-size: 11.0pt\">numbers = fs.GetFolder(folderName).Files.Count<\/span><span style=\"font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'\"><br \/>\n<\/span><span style=\"font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-size: 11.0pt\">if (numbers > 2) Then<\/span><span style=\"font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'\"><br \/>\n<\/span><span style=\"font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-size: 11.0pt\">Const EVENT_WARNING = 2<\/span><span style=\"font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'\"><br \/>\n<\/span><span style=\"font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-size: 11.0pt\">Set objShell = CreateObject(&#8220;Wscript.Shell&#8221;)<\/span><span style=\"font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'\"><br \/>\n<\/span><span style=\"font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-size: 11.0pt\">objShell.LogEvent 2, &#8220;There are more than 2 files in the directory. The directory is &#8221; &#038; folderName &#038; &#8220;. Number of files are &#8221; &#038; numbers\u00c2\u00a0<\/span><span style=\"font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-size: 11.0pt\"> <\/span><span style=\"font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'\">End If<\/span><span style=\"font-family: 'Verdana','sans-serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'\">\u00c2\u00a0<\/span><span style=\"font-family: 'Verdana','sans-serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'\"><\/p>\n<p \/><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is a script that will count file in a directory. If there is more than X file in the directory a event will be generated in the local event viewer. You can create a event rule that runs the script and a collection rule that collections event ID 2 from your machine. The local &hellip; <a href=\"http:\/\/contoso.se\/blog\/?p=57\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","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\/57"}],"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=57"}],"version-history":[{"count":0,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/57\/revisions"}],"wp:attachment":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=57"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=57"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=57"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}