Full Disk Space on Site Server (IIS Logs)

Many times I saw site server with a full C:\ drive. The most common problem is that the internet information services (IIS) logs are growing without a limit.

 

image

 

These log files are normally stored under c:\inetpub\logs\LogFiles. What options do we have to solve this problem and get a solution for the future?

  1. Delete the logs manually on a periodic schedule
  2. Disable the IIS Logs
  3. Create a Task Scheduler entry on all IIS servers and run a script
  4. Create a Configuration Manager Settings Management Item

Option one and two are not really a solution. With option three we need manual actions on a server or a bigger script to create the scheduled task. Additionally it’s not possible to monitor these tasks centrally. So I will focus on the last option, which will use the Settings Management feature of Configuration Manager with a remediation action.


The following Script checks if there are file older than 7 days, then it reports a NonCompliance Value, otherwise Compliant.

if(Test-Path C:\inetpub\logs\LogFiles){<br />
$files = get-childitem -Path C:\inetpub\logs\LogFiles -recurse | where-object {$_.lastwritetime -lt (get-date).addDays(-7) -and $_.Name -like &quot;%.log&quot;}<br />
$filesFound = $false<br />
$files | Foreach-Object { $filesFound = $true }</p>
<p>if($filesFound){<br />
Write-Host &quot;NotCompliant&quot;<br />
} else {<br />
Write-Host &quot;Compliant&quot;<br />
}<br />
}else {<br />
Write-Host &quot;Compliant&quot;<br />
}

To remediate and delete the older files I use this script:

$files = get-childitem -Path C:\inetpub\logs\LogFiles -recurse | where-object {$_.lastwritetime -lt (get-date).addDays(-7) -and $_.Name -like &quot;%.log&quot;}<br />
$filesFound = $false<br />
$files | Foreach-Object { Remove-Item $files -force }

Now you can create a settings management item and check how much disk space you could save, when you delete your IIS Log files. You can also download the settings management item here and import it to your ConfigMgr Environment. Before activating the remediation action try it out on some server for your own security.

 

Thomas Kurth
Follow me

Thomas Kurth

Principal Workplace Consultant at baseVISION AG
I’m a consultant, trainer and architect for workplace management and enterprise mobility projects with Microsoft Technologies in the past eight years. I love to push and design the modern workplace based on Windows 10, EM&S and O365 for my customers which is the only answer for the current security threats, agile world and the fast-changing business requirements of my customers. Important for me is to simplify and automate the operational processes, because there are the highest costs.

MCSEMCTCMCE
Thomas Kurth
Follow me