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 ServicesStop-Service -Name ccmsetup -Force -ErrorAction SilentlyContinueStop-Service -Name CcmExec -Force -ErrorAction SilentlyContinueStop-Service -Name smstsmgr -Force -ErrorAction SilentlyContinueStop-Service -Name CmRcService -Force -ErrorAction SilentlyContinue
$CCMProcess = Get-Process ccmexec -ErrorAction SilentlyContinuetry{
$CCMProcess.WaitForExit()
}catch{
}
# Remove WMI NamespacesGet-WmiObject -Query "SELECT * FROM __Namespace WHERE Name='ccm'" -Namespace root | Remove-WmiObjectGet-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 SilentlyContinueRemove-Item -Path $CurrentPath\CcmExec -Force -Recurse -ErrorAction SilentlyContinueRemove-Item -Path $CurrentPath\smstsmgr -Force -Recurse -ErrorAction SilentlyContinueRemove-Item -Path $CurrentPath\CmRcService -Force -Recurse -ErrorAction SilentlyContinue
$CurrentPath = “HKLM:\SOFTWARE\Microsoft”Remove-Item -Path $CurrentPath\CCM -Force -Recurse -ErrorAction SilentlyContinueRemove-Item -Path $CurrentPath\CCMSetup -Force -Recurse -ErrorAction SilentlyContinueRemove-Item -Path $CurrentPath\SMS -Force -Recurse -ErrorAction SilentlyContinue
Remove-Item -Path $CurrentPath\DeviceManageabilityCSP -Force -Recurse -ErrorAction SilentlyContinue
$CurrentPath = $env:WinDirRemove-Item -Path $CurrentPath\CCM -Force -Recurse -ErrorAction SilentlyContinueRemove-Item -Path $CurrentPath\ccmsetup -Force -Recurse -ErrorAction SilentlyContinueRemove-Item -Path $CurrentPath\ccmcache -Force -Recurse -ErrorAction SilentlyContinueRemove-Item -Path $CurrentPath\SMSCFG.ini -Force -ErrorAction SilentlyContinueRemove-Item -Path $CurrentPath\SMS*.mif -Force -ErrorAction SilentlyContinueRemove-Item -Path $CurrentPath\SMS*.mif -Force -ErrorAction SilentlyContinue
Help Center