"Uninstalling and Removing Configuration Manager (SCCM) Client"
This PowerShell script is designed to uninstall the SCCM client (System Center Configuration Manager) from a system. It begins by checking if the ccmsetup.exe file exists and then proceeds with the uninstallation process. It also forcefully stops associated services, such as ccmsetup, CcmExec, smstsmgr, and CmRcService.
Additionally, the script removes relevant WMI namespaces (ccm and sms) and deletes associated registry keys and directories under C:\Windows and HKLM:\SOFTWARE\Microsoft. This cleanup ensures that all traces of the SCCM client are removed from the system, including files like SMSCFG.ini and other configuration files.
HERE IS THE SCRIPT:
$CCMpath = ‘C:\Windows\ccmsetup\ccmsetup.exe’
if (Test-Path $CCMpath) {
Start-Process -FilePath $CCMpath -Args “/uninstall” -Wait -NoNewWindow
$CCMProcess = Get-Process ccmsetup -ErrorAction SilentlyContinue
try{ $CCMProcess.WaitForExit() }catch{
} }
Stop Services
Section titled “Stop Services”Stop-Service -Name ccmsetup -Force -ErrorAction SilentlyContinue Stop-Service -Name CcmExec -Force -ErrorAction SilentlyContinue Stop-Service -Name smstsmgr -Force -ErrorAction SilentlyContinue Stop-Service -Name CmRcService -Force -ErrorAction SilentlyContinue
$CCMProcess = Get-Process ccmexec -ErrorAction SilentlyContinue try{
$CCMProcess.WaitForExit()
}catch{
}
Remove WMI Namespaces
Section titled “Remove WMI Namespaces”Get-WmiObject -Query “SELECT * FROM __Namespace WHERE Name=‘ccm’” -Namespace root | Remove-WmiObject Get-WmiObject -Query “SELECT * FROM __Namespace WHERE Name=‘sms’” -Namespace root\cimv2 | Remove-WmiObject
$CurrentPath = “HKLM:\SYSTEM\CurrentControlSet\Services” Remove-Item -Path $CurrentPath\CCMSetup -Force -Recurse -ErrorAction SilentlyContinue Remove-Item -Path $CurrentPath\CcmExec -Force -Recurse -ErrorAction SilentlyContinue Remove-Item -Path $CurrentPath\smstsmgr -Force -Recurse -ErrorAction SilentlyContinue Remove-Item -Path $CurrentPath\CmRcService -Force -Recurse -ErrorAction SilentlyContinue
$CurrentPath = “HKLM:\SOFTWARE\Microsoft” Remove-Item -Path $CurrentPath\CCM -Force -Recurse -ErrorAction SilentlyContinue Remove-Item -Path $CurrentPath\CCMSetup -Force -Recurse -ErrorAction SilentlyContinue Remove-Item -Path $CurrentPath\SMS -Force -Recurse -ErrorAction SilentlyContinue
Remove-Item -Path $CurrentPath\DeviceManageabilityCSP -Force -Recurse -ErrorAction SilentlyContinue
$CurrentPath = $env:WinDir Remove-Item -Path $CurrentPath\CCM -Force -Recurse -ErrorAction SilentlyContinue Remove-Item -Path $CurrentPath\ccmsetup -Force -Recurse -ErrorAction SilentlyContinue Remove-Item -Path $CurrentPath\ccmcache -Force -Recurse -ErrorAction SilentlyContinue Remove-Item -Path $CurrentPath\SMSCFG.ini -Force -ErrorAction SilentlyContinue Remove-Item -Path $CurrentPath\SMS*.mif -Force -ErrorAction SilentlyContinue Remove-Item -Path $CurrentPath\SMS*.mif -Force -ErrorAction SilentlyContinue