When transitioning Windows endpoints from Microsoft Configuration Manager (SCCM/MEMCM) co-management to 100% cloud-native Microsoft Intune, lingering SCCM client remnants frequently block Windows Update for Business (WUfB) policies from taking effect. This guide provides the complete cleanup procedure and PowerShell detection/remediation script to cleanly retire the legacy SMS Agent and restore Intune update orchestration.
Script to Uninstall SCCM from Devices through Intune
Detection Script:
# Check for SCCM client presence
$path = Test-Path -Path "C:\Windows\ccmsetup\ccmsetup.exe"
if ($path) {
Write-Host "SCCM Client Exists. Running Remediation."
Exit 1 # Indicates that remediation is needed
} else {
Write-Host "SCCM Client Does Not Exist."
Exit 0 # Indicates no remediation needed
}Explanation:
The detection script checks whether the SCCM client setup file exists by testing the path. It exits with a code 1 if the file is found, indicating the need for remediation, otherwise it exits with a code 0.
Remediation Script:
Write-Host "Starting SCCM Client Uninstallation Process" -ForegroundColor Yellow
# Initialize a success flag
$success = $true
Try {
# Uninstall SCCM Client
Write-Host "Uninstalling SCCM Client..." -ForegroundColor Yellow
if (Test-Path -Path "C:\Windows\ccmsetup\ccmsetup.exe") {
Start-Process -FilePath C:\Windows\ccmsetup\ccmsetup.exe -ArgumentList "/uninstall" -Wait -ErrorAction Stop
}
# Wait briefly for uninstallation to complete
Start-Sleep -Seconds 10
# Stop SCCM services and processes if they exist
if (Get-Service ccmexec -ErrorAction SilentlyContinue) {
Write-Host "Stopping SCCM Service: ccmexec" -ForegroundColor Yellow
Stop-Service ccmexec -Force -ErrorAction Stop
}
if (Get-Process ccmsetup -ErrorAction SilentlyContinue) {
Write-Host "Stopping SCCM Setup Process: ccmsetup" -ForegroundColor Yellow
Stop-Process -Name ccmsetup -Force -ErrorAction Stop
}
# Wait again for cleanup tasks to complete
Start-Sleep -Seconds 10
# Remove SCCM directories
Write-Host "Removing SCCM directories..." -ForegroundColor Yellow
Remove-Item -Path "$($Env:WinDir)\CCM" -Force -Recurse -ErrorAction SilentlyContinue
Remove-Item -Path "$($Env:WinDir)\CCMSetup" -Force -Recurse -ErrorAction SilentlyContinue
Remove-Item -Path "$($Env:WinDir)\CCMCache" -Force -Recurse -ErrorAction SilentlyContinue
# Remove SCCM configuration file
Write-Host "Removing SCCM configuration files..." -ForegroundColor Yellow
Remove-Item -Path "$($Env:WinDir)\smscfg.ini" -Force -Recurse -ErrorAction SilentlyContinue
# Remove SCCM registry keys
Write-Host "Removing SCCM registry keys..." -ForegroundColor Yellow
$registryPaths = @(
'HKLM:\Software\Microsoft\SystemCertificates\SMS\Certificates\*',
'HKLM:\SOFTWARE\Microsoft\CCM',
'HKLM:\SOFTWARE\Wow6432Node\Microsoft\CCM',
'HKLM:\SOFTWARE\Microsoft\SMS',
'HKLM:\SOFTWARE\Wow6432Node\Microsoft\SMS',
'HKLM:\Software\Microsoft\CCMSetup',
'HKLM:\Software\Wow6432Node\Microsoft\CCMSetup',
'HKLM:\SYSTEM\CurrentControlSet\Services\CcmExec'
)
foreach ($path in $registryPaths) {
Remove-Item -Path $path -Force -Recurse -ErrorAction SilentlyContinue
}
# Wait for WMI namespace updates
Start-Sleep -Seconds 5
# Remove SCCM-related WMI namespaces
Write-Host "Removing SCCM WMI namespaces..." -ForegroundColor Yellow
$wmiNamespaces = @(
"Select * From __Namespace Where Name='CCM'",
"Select * From __Namespace Where Name='CCMVDI'",
"Select * From __Namespace Where Name='SmsDm'",
"Select * From __Namespace Where Name='sms'"
)
foreach ($query in $wmiNamespaces) {
Get-CimInstance -Query $query -Namespace "root" -ErrorAction SilentlyContinue | Remove-CimInstance -ErrorAction SilentlyContinue
}
Write-Host "SCCM Uninstallation Process Completed Successfully." -ForegroundColor Green
# Final wait to handle Intune timing/sync delay
Write-Host "Waiting briefly to ensure sync with Intune..." -ForegroundColor Yellow
Start-Sleep -Seconds 30
} Catch {
Write-Host "An error occurred during SCCM removal: $($_.Exception.Message)" -ForegroundColor Red
$success = $false
}
# Exit with success or failure code
if ($success) {
Exit 0 # Indicates success
} else {
Exit 1 # Indicates failure
}Explanation:
The remediation script performs uninstallation of the SCCM client, stops related services, deletes their associated directories, configuration files, registry keys, and WMI namespaces. Each step is logged to the host to provide feedback during execution, ensuring the legacy SCCM components are thoroughly cleaned.