After a couple of weeks of running an SCCM server, you may get the C:\ drive full. What are the best practices to save disk space on an SCCM server? The first thing we check is how much space is filled by SCCM IIS log files. Usually, it takes a couple of GB on the drive. It’s an absolute must to implement solutions to delete SCCM IIS logs files from your primary server.
The SCCM IIS logs files are usually in C:\Inetpub\Logs\LogFiles and are increasing at a rapid pace. In my lab environment with 50 clients, it’s growing at about 1MB per day. Not much… but on an SCCM site, I’m actually managing with a couple of thousand clients, it grows 150 MB a day. It could fill up a drive pretty quickly.
There are numerous ways to manage SCCM IIS log files :
- Delete the logs manually or use a scheduled task
- Use a Powershell script
- Disable the IIS Logs completely
- Enable Folder Compression
- Use the IISLogCleaner tool
Delete SCCM IIS Logs Files Manually
SCCM IIS log files are mainly for troubleshooting and reviewing security. If neither are of immediate interest to you, then you can turn off logging or write a script to delete them. An easy way to do this is by using the Foreach command in a Windows Server Task Scheduler. We will delete all IIS log files that are older than 30 days :
- On your SCCM server, start Task Scheduler
- On the right pane, select Create Basic Task
- On the Create Basic Task Wizard, name your task and click Next
- On the Trigger section, select Weekly
- Select the desired schedule. We select to run every Sunday
- In the Action section, select Start a program
- In the Start a Program section, entrer the following command : Forfiles.exe -p C:\inetpub\logs\LogFiles\W3SVC1 -m *.log -d -30 -c “Cmd.exe /C del @path\”
- You can change the number of days if desired (30)
- It’s important to select Yes in the warning, it will split your command to fill the Add Argument section
You can test your job by running your job manually or wait for the schedule to trigger the task. After running you should have no file older than 30 days and should free some space from your drive.
Delete SCCM IIS Log Files using PowerShell or VBS Script
You can also delete SCCM IIS logs file using PowerShell or VBS script. Here are 3 scripts that work fine and which can also be used with a Configuration Item in order to run when your server is not compliant. Pick the one that fits your needs :
Disable IIS logging
If you really don’t care about keeping SCCM IIS logs files, you can disable it completely in IIS Manager or redirect the log files to another drive : (We do not recommend disabling it, it won’t hurt SCCM directly but you could be unable to run some report (IE : Distribution Point utilization) which are based on these files.)
- Open IIS Manager
- On the left pane, select your server
- On the right pane, select Logging
- In the Logging pane, click Disable in the Actions section
- If you prefer to change the log file location, you can do it by typing the new location in the Directory box
Enable Folder Compression
Enabling folder compression won’t free up space but could help if you don’t want to delete the files (IIS log files compress to about 2% of their original size). You must be an administrator to perform this procedure :
- Click the File Manager icon in the icon bar
- Move to the folder containing IIS log files (by default, C:\inetpub\logs\LogFiles)
- Right-click on the folder and click Properties
- On the General tab of the Properties page, click Advanced
- Click Compress contents to save disk space, and then click OK
- Click Apply, and then select whether to compress the folder only, or the folder, its subfolders, and its files.
- Click OK.
Verify that the folder contents are compressed. The name of the folder and the name of each file should be colored in blue, and the size of a compression file should be smaller.
IISLogCleaner is a simple tool to enable a log retention policy for IIS. The tool runs in the background and cleans the IIS log folder automatically older than a maximum age. This is a third-party tool that is not supported by Microsoft.
- Download the executable
- Execute IISLogCleaner.exe
- Open the settings.txt file with a text editor to make configuration changes or right-click the IIS icon in the notification area, and then click Settings
- Right-click the IIS icon in the notifications area, and then click Paused to un-pause the application.
We actually have another W3SVC1 Folder (due to the WSUS installation), keep in mind to empty those log files as well 😉
There is a typo in the command. A backslash crept in between the -c and the “cmd.exe…”
Forfiles.exe -p C:\inetpub\logs\LogFiles\W3SVC1 -m *.log -d -30 -c \”Cmd.exe /C del @path\”
Forfiles.exe -p C:\inetpub\logs\LogFiles\W3SVC1 -m *.log -d -30 -c “Cmd.exe /C del @path\”
You’re right. I updated the blog post. Thanks for your input !