{"id":44,"date":"2015-01-24T19:44:09","date_gmt":"2015-01-25T00:44:09","guid":{"rendered":"http:\/\/packetlost.com\/blog\/?p=44"},"modified":"2017-04-14T20:36:07","modified_gmt":"2017-04-15T00:36:07","slug":"cleanup-iis-logs-automagically","status":"publish","type":"post","link":"https:\/\/packetlost.com\/blog\/2015\/01\/24\/cleanup-iis-logs-automagically\/","title":{"rendered":"Cleanup IIS Logs AutoMagically"},"content":{"rendered":"<p>First head over to the <a href=\"https:\/\/gallery.technet.microsoft.com\/scriptcenter\/Delete-files-older-than-x-13b29c09\" target=\"_blank\">Microsoft Script Gallery and grab deleteold.ps1 by Jaap Brasser<\/a>.<\/p>\n<p>I tend to copy scripts to c:\\scripts on systems so I copied deleteold.ps1 there and created two new batch files there as well.<\/p>\n<p>The first was used to launch the powershell script with switches that will delete all files in the IIS Logs directory older than 90 days and append to a log of all actions taken.<\/p>\n<p><strong>IISLogsCleanUp.bat<\/strong> :<\/p>\n<pre class=\"lang:batch decode:true\" title=\"IISLogsCleanUp.bat\">powershell.exe -ExecutionPolicy bypass -File C:\\scripts\\deleteold.ps1 -FolderPath C:\\inetpub\\logs -FileAge 90 -VerboseLog -AppendLog -LogFile \"C:\\scripts\\logcleanup.log\"\r\n<\/pre>\n<p>The second batch file registers a task that runs this script weekly. Right click this batch and run as administrator and IIS logs will no longer be a thorn in your side.<\/p>\n<p><strong>IISLogCleanUpTaskReg.bat :<br \/>\n<\/strong><\/p>\n<pre class=\"lang:batch decode:true \" title=\"IISLogCleanUpTaskReg.bat\">schtasks \/create \/tn \"CleanUpIISLogs\" \/ru \"SYSTEM\" \/tr \"c:\\scripts\\IISLogsCleanUp.bat\" \/sc weekly \/mo 1 \/d SUN \/st 05:01<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>As usual, customize as needed! Next on my list is for this repetitive task is creating a powershell remoting script to copy these files to remote servers and execute the task register command.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>First head over to the Microsoft Script Gallery and grab deleteold.ps1 by Jaap Brasser. I tend to copy scripts to c:\\scripts on systems so I copied deleteold.ps1 there and created two new batch files there as well. The first was &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/packetlost.com\/blog\/2015\/01\/24\/cleanup-iis-logs-automagically\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,2],"tags":[20,3],"class_list":["post-44","post","type-post","status-publish","format-standard","hentry","category-iis","category-powershell","tag-automation","tag-powershell"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/posts\/44","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/comments?post=44"}],"version-history":[{"count":5,"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/posts\/44\/revisions"}],"predecessor-version":[{"id":169,"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/posts\/44\/revisions\/169"}],"wp:attachment":[{"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/media?parent=44"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/categories?post=44"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/tags?post=44"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}