Clean up IIS log in SharePoint Server

0
688
Sometimes you may experience an issue with Disk storage exceeding due to IIS log files on your servers. This is the good time to clear the log file of IIS. I have done a scheduled job for my all servers by using the Task Scheduler.
Follow the following steps to schedule a cleanup job for IIS log files.
Open notepad, copy and paste following command.
get-childitem -Path C:inetpublogsLogFiles -recurse | where-object {$_.lastwritetime -lt (get-date).addDays(-15)} | Foreach-Object { del $_.FullName }
Then save file with extension .ps1 (Ex: Remove-IISLogfiles.ps1) to your server so it can be referred to run later. In my case, I place it at C:inetpublogsScriptRemove-IISLogfiles.ps1
From the server, open Task Manager. And follow following pictures to complete the task.




From Edit Action, use following command and argument
Program/script: %SystemRoot%system32WindowsPowerShellv1.0powershell.exe
And arguments (optional): C:inetpublogsScriptRemove-IISLogfiles.ps1 -noprofile – Noninteractive
Note: you can force run above command without stuck in console windows (sometime it happen when power-shell command travels to child folders) by using the following argument in  And arguments (optional) text-box: powershell.exe -executionpolicy unrestricted C:inetpublogsScriptRemove-IISLogfiles.ps1 -noprofile – Noninteractive


You are done!