Monday, March 19, 2018

Scripting the automation of the Content Library Cleanup Tool

As of SCCM 1702's release, the Content Library Cleanup Tool is a nifty addition to cleanup your distribution points painlessly and effectively.  Since it requires command line parameters to run, I have created scripts to run the tool easier without having to remember the parameters.  There are two modes, 'what-if' and 'delete' modes for the tool, and I've created batch scripts for each mode and named them respectively.

For 'delete' mode, here is the batch script ("CLCT-Delete.cmd"):
@echo off
set /p dp="Please specify the DP hostname.  Hit Enter for %COMPUTERNAME%: "
if [%dp%] == [] ( goto default ) else (
"%~dp0ContentLibraryCleanup.exe" /dp %dp% /delete /log "%~dp0Logs\%dp%"
goto exit
)
:default
"%~dp0ContentLibraryCleanup.exe" /dp %COMPUTERNAME%.domain.com /delete /log "%~dp0Logs\%COMPUTERNAME%"
:exit
pause
exit 

For 'what-if' mode, here is the script ("CLCT-WhatIf.cmd"):

@echo off
setlocal EnableDelayedExpansion
set /p dp="Please specify the DP hostname.  Hit Enter for %COMPUTERNAME%: "
if [%dp%] == [] ( goto default ) else (
"%~dp0ContentLibraryCleanup.exe" /dp %dp% /log "%~dp0Logs\%dp%"
goto exit
)
:default
"%~dp0ContentLibraryCleanup.exe" /dp %COMPUTERNAME%.domain.com /log "%~dp0Logs\%COMPUTERNAME%"
:exit
pause
exit 


The script assumes "ContentLibraryCleanup.exe" is in the same folder as the script.  It will prompt for the hostname of the distribution point, and if none is entered, uses the current machine's hsotname as default.  It then writes everything to a log file in Logs\<hostname> folder as well (and opens it automatically when done).

Note: The Tool will crash if any content is currently being distributed to the DP (and it will do this after it's processed all content, which takes awhile).  Refer to the link above for more details if needed.

No comments:

Post a Comment