A little bit of ConfigMgr housekeeping

Just wanted to post a quick reminder that ConfigMgr by default is logging info not only to it's own log files, which are in the ConfigMgr installation directory, which is typically not on the C: drive, at least, should not be on the C: drive, but also to the IIS logs, which typically are on the C: drive. Obviously it is not good if the C: fills up, because then the site server dies. So some house-keeping is useful.

Moving the ConfigMgr installation folder

If you by mistake installed ConfigMgr itself to the C: drive, that should be addressed. ConfigMgr inboxes can fill up pretty quickly if you run into issues in the environment. To fix the issue, you can use the ConfigMgr backup/restore process to move the installation directory to a folder on a data volume. You should also make sure to place a NO_SMS_ON_DRIVE.SMS file on the C: drive, so ConfigMgr doesn't try to use it.

Note: You can only specify a different installation path for the backup restore for ConfigMgr 2012 R2 or later. For earlier versions of ConfigMgr, when restoring a backup, you had to to use the same path.

Configuring IIS Logs for ConfigMgr

In a ConfigMgr environment the IIS logs are mainly for troubleshooting and reviewing security, and can be quite useful for troubleshooting too. But you typically don't need to store them forever, since troubleshooting for example why a client can't download a package, is often something you do in the moment, when you have the problem.

Obviously, you can disable IIS logging all together, which is done in the IIS console. But since the logs are quite useful to have, I instead recommend using a script to delete them periodically. In this section you find two solutions to do that. The first is a configuration item for ConfigMgr, the second is running a PowerShell script using a scheduled task in Windows.

Using a Configuration Item

Configuration items in ConfigMgr is a very powerful way to run scripts, not only to give compliance info, but also to remediate and configure things on the machines. In this section you find a configuration item you can import that periodically deletes old log files in IIS.

This original ConfigMgr Configuration Item was graciously provided by Terence Beggs (@terencebeggs). Credits also goes to Maurice Daly (@modaly_it) and Sergey Korotkov (@sekorotkov) for helping tweaking the script.

The remediation script in the ConfigMgr CI (with the nice syntax high-lighting introduced in ConfigMgr 2010)

Download it here: https://deploymentresearch.com/DRFiles/CI-Cleanup-IIS-Logs.cab

Using a Scheduled Task (and PowerShell)

For those of you not using ConfigMgr, a script I found very useful is PowerShell script by Stephen Owen (@FoxDeploy) which is available on Script Center: http://gallery.technet.microsoft.com/scriptcenter/Automatically-clean-up-old-8d35fdfd You can also get it from his blog directly: http://foxdeploy.com/2015/02/11/automatically-delete-old-iis-logs-w-powershell/

I modified Stephen's script a bit to work in my environment, here is the modified version:

$LogPath = "C:\inetpub\logs"
$maxDaystoKeep = -30
$outputPath = "C:\Setup\Cleanup_IIS_logs.log"

$itemsToDelete = dir $LogPath -Recurse -File *.log | Where LastWriteTime -lt ((get-date).AddDays($maxDaystoKeep))

if ($itemsToDelete.Count -gt 0){
    ForEach ($item in $itemsToDelete){
        "$($item.BaseName) is older than $((get-date).AddDays($maxDaystoKeep)) and will be deleted" | Add-Content $outputPath
        Remove-Item $item.FullName -Force
    }
}
else{
    "No items to be deleted today $($(Get-Date).DateTime)"  | Add-Content $outputPath
    }

Write-Output "Cleanup of log files older than $((get-date).AddDays($maxDaystoKeep)) completed..."
start-sleep -Seconds 10

To create a scheduled task that runs the script every day at 5am, you can use the following PowerShell command:

& schtasks /create /ru "system" /sc DAILY /ST 05:00  /tn "IIS Log Cleanup" /TR "PowerShell.exe -ExecutionPolicy ByPass -File C:\Setup\Housekeeping\IISLogCleanup.ps1"
Log from the Cleanup IIS Logs script.

/ Johan

About the author

Johan Arwidmark

0 0 votes
Article Rating
Subscribe
Notify of
guest
2 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Sergey Korotkov
2 years ago

Little bit fix CI:
$IISSites = Get-Website -> $IISSites = @(Get-Website)


>