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){
$files = get-childitem -Path C:\inetpub\logs\LogFiles -recurse | where-object {$_.lastwritetime -lt (get-date).addDays(-7) -and $_.Name -like "%.log"}
$filesFound = $false
$files | Foreach-Object { $filesFound = $true }

if($filesFound){
Write-Host "NotCompliant"
} else {
Write-Host "Compliant"
}
}else {
Write-Host "Compliant"
}

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 "%.log"}
$filesFound = $false
$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 work for workplace management and enterprise mobility projects with Microsoft Technologies since seven years. Important for me is to simplify and automate the operational processes, because there are the heighest costs.

MCSEMCTCMCE
Thomas Kurth
Follow me