You are here:   Research
  |  Login

Welcome to my blog, quickest way to find articles is usually to search for them.

Minimize
Search in All Title Contents
 
     

A little bit of ConfigMgr housekeeping

Nov 07 2016

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.

The ConfigMgr Configuration Item was graciously provided by Terence Beggs (@terencebeggs), and credits also goes to Maurice Daly (@modaly_it) for helping tweaking the script.

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

 

image
The configuration item imported to ConfigMgr.

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: https://gallery.technet.microsoft.com/scriptcenter/Automatically-clean-up-old-8d35fdfd You can also get it from his blog directly: https://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 E:\Setup\Housekeeping\IISLogCleanup.ps1" 

image
The log from running the cleanup PowerShell script.

/ Johan








Happy deployment, and thanks for reading!


What our lawyers makes us say:

This information is provided "AS IS" with no warranties, confers no rights and is not supported by the authors or Deployment Artist.

Copyright © 2017 by Deployment Artist (the company behind deployment research). All rights reserved. No part of the information on this web site may be reproduced or posted in any form or by any means without the prior written permission of the publisher.

Shorthand: Don't pass off our work as yours, it's not nice.

Blog Archive

Minimize