In some cases, it is necessary to uninstall the SCCM client after an operating system deployment has completed. In this case, you can use these two scripts to facilitate this task. Just add a Run Command Line task at the end of your OSD sequence that references a regular SCCM package containing these files and runs the ConfigureForCleanup.cmd script. Then, ten minutes after the next time the computer is rebooted, the SCCM client will be removed.


mkdir %Windir%\Scripts
copy "%~dp0CleanupSCCM.cmd" %windir%\Scripts

schtasks /create /tn "Clean Off SCCM Client" /RU SYSTEM /RP "" /SC ONSTART /DELAY 0010:00 /RL HIGHEST /TR %Windir%\Scripts\CleanupSCCM.cmd


@echo off

echo. *************************
echo. * Clean off SCCM Client *
echo. *************************

echo. Saving current SCCM logs into the C:\Windows\Temp\DeploymentLogs1 folder for reference...
pushd %windir%\ccm\logs
mkdir %windir%\temp\DeploymentLogs1
copy /y *.* %windir%\temp\DeploymentLogs1

echo. Calling out to the SCCM client uninstall utility. This will take a few minutes to complete...
pushd %windir%\ccmsetup
start /wait "" ccmsetup.exe /uninstall

echo. Waiting 30 seconds for processes to be fully terminated and locks released...
timeout /t 30

echo. Deleting SCCM client folders from the computer...
rmdir /s /q %windir%\ccmcache
rmdir /s /q %windir%\ccm
rmdir /s /q %windir%\ccmsetup
if exist "%ProgramData%\Microsoft\Windows\Start Menu\Programs\Microsoft System Center" rmdir /s /q "%ProgramData%\Microsoft\Windows\Start Menu\Programs\Microsoft System Center"

echo. Removing the scheduled task that ran this script because it shouldn't be needed any longer...
schtasks /delete /TN "Clean Off SCCM Client" /F

echo. All finished!
timeout /t 5