Remove All Traces of Microsoft SCCM w/ PowerShell (By Force) (2024)

Remove All Traces of Microsoft SCCM w/ PowerShell (By Force) (1)

Microsoft’s System Center Configuration Manager (SCCM) seems to usually work pretty well for 95-97% of the computers at the environments I’ve worked in. Unfortunately for the remaining few percentage points of computers that SCCM is *not* working pretty well for when SCCM does break it does so spectacularly with style and pizzazz.

This script was developed for those computers. It first tries to uninstall SCCM gracefully if the installer is present, but regardless of whether it fails or not afterward it will wipe all traces of SCCM from the hard drive and registry. This allows you to do a new “clean” installation of SCCM afterward on machines that would not let you previously reinstall.

We are going to use PowerShell to accomplish this and explain each step in this guide!

Running SCCM Uninstaller

It’s usually a good idea to let SCCM try to uninstall itself even if we are going to forcefully remove everything anyways later. The SCCM uninstaller, being officially supported, knows every trace that should be on there and has a much easier time stopping everything than we will.

I broke my code up into “functions”. Go ahead and create a new PowerShell .ps1 file:

# Attempt to run the SCCM uninstallerfunction uninstallSCCM() { if (Test-Path -Path "$Env:SystemDrive\Windows\ccmsetup\ccmsetup.exe") { # Stop SCCM services Get-Service -Name CcmExec -ErrorAction SilentlyContinue | Stop-Service -Force -Verbose Get-Service -Name ccmsetup -ErrorAction SilentlyContinue | Stop-Service -Force -Verbose # Run the SCCM uninstaller Start-Process -FilePath "$Env:SystemDrive\Windows\ccmsetup\ccmsetup.exe" -ArgumentList '/uninstall' # Wait for the uninstaller to finish do { Start-Sleep -Milliseconds 1000 $Process = (Get-Process ccmsetup -ErrorAction SilentlyContinue) } until ($null -eq $Process) Write-Host "SCCM uninstallation completed" }}uninstallSCCM

This piece of the guide isn’t too difficult to explain so we won’t go into too much detail. Basically first we stop SCCM’s services (CCMExec and CCMSetup) and then we launch the uninstaller. If the SCCM uninstaller is present it will always be in the Windows\ccmsetup folder.

The “do” loop just sleeps for 1000 milliseconds and then checks to see if the uninstaller is done. Once it is it writes a line to the host console to let us know the uninstallation has finished. The very last line of the script calls the “uninstallSCCM” function we created above. Pretty simple!

One possible exception to trying the graceful uninstallation first is if the uninstaller isn’t working/freezing/stuck. I’ve seen some computers occasionally where the uninstaller will run and literally never finish even if you leave it overnight. If this is the case you may need to jump straight to manual removal otherwise try letting it finish.

Force Removal of SCCM

Next we are going to forcefully remove all SCCM files, registry traces, certificates, caches, WMI namespaces, etc. Let’s create a new function called “removeSCCM”:

# Forcefully remove all traces of SCCM from the computerfunction removeSCCM() { # Stop SCCM services Get-Service -Name CcmExec -ErrorAction SilentlyContinue | Stop-Service -Force -Verbose Get-Service -Name ccmsetup -ErrorAction SilentlyContinue | Stop-Service -Force -Verbose # Take ownership of/delete SCCM's client folder and files $null = takeown /F "$($Env:WinDir)\CCM" /R /A /D Y 2>&1 Remove-Item -Path "$($Env:WinDir)\CCM" -Force -Recurse -Confirm:$false -Verbose -ErrorAction SilentlyContinue # Take ownership of/delete SCCM's setup folder and files $null = takeown /F "$($Env:WinDir)\CCMSetup" /R /A /D Y 2>&1 Remove-Item -Path "$($Env:WinDir)\CCMSetup" -Force -Recurse -Confirm:$false -Verbose -ErrorAction SilentlyContinue # Take ownership of/delete SCCM cache of downloaded packages and applications $null = takeown /F "$($Env:WinDir)\CCMCache" /R /A /D Y 2>&1 Remove-Item -Path "$($Env:WinDir)\CCMCache" -Force -Recurse -Confirm:$false -Verbose -ErrorAction SilentlyContinue

First we need to take ownership of the SCCM client/setup/cache folders to avoid getting permission errors when we remove them. After taking ownership we remove all the files recursively with one command using the -Recurse switch of Remove-Item. That’s it for the files, now let’s get the registry:

 # Remove CCM registry keys Remove-Item -Path 'HKLM:\SOFTWARE\Microsoft\CCM' -Force -Recurse -Verbose -ErrorAction SilentlyContinue Remove-Item -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\CCM' -Force -Recurse -Confirm:$false -Verbose -ErrorAction SilentlyContinue # Remove SMS registry keys Remove-Item -Path 'HKLM:\SOFTWARE\Microsoft\SMS' -Force -Recurse -Confirm:$false -Verbose -ErrorAction SilentlyContinue Remove-Item -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\SMS' -Force -Recurse -Confirm:$false -Verbose -ErrorAction SilentlyContinue # Remove CCMSetup registry keys Remove-Item -Path 'HKLM:\Software\Microsoft\CCMSetup' -Force -Recurse -Confirm:$false -Verbose -ErrorAction SilentlyContinue Remove-Item -Path 'HKLM:\Software\Wow6432Node\Microsoft\CCMSetup' -Force -Confirm:$false -Recurse -Verbose -ErrorAction SilentlyContinue

That’s it for all the registry keys. Let’s remove the services and the WMI namespaces next:

 # Remove CcmExec and ccmsetup services Remove-Item -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\CcmExec' -Force -Recurse -Confirm:$false -Verbose -ErrorAction SilentlyContinue Remove-Item -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\ccmsetup' -Force -Recurse -Confirm:$false -Verbose -ErrorAction SilentlyContinue # Remove SCCM namespaces from WMI repository Get-CimInstance -Query "Select * From __Namespace Where Name='CCM'" -Namespace "root" -ErrorAction SilentlyContinue | Remove-CimInstance -Verbose -Confirm:$false -ErrorAction SilentlyContinue Get-CimInstance -Query "Select * From __Namespace Where Name='CCMVDI'" -Namespace "root" -ErrorAction SilentlyContinue | Remove-CimInstance -Verbose -Confirm:$false -ErrorAction SilentlyContinue Get-CimInstance -Query "Select * From __Namespace Where Name='SmsDm'" -Namespace "root" -ErrorAction SilentlyContinue | Remove-CimInstance -Verbose -Confirm:$false -ErrorAction SilentlyContinue Get-CimInstance -Query "Select * From __Namespace Where Name='sms'" -Namespace "root\cimv2" -ErrorAction SilentlyContinue | Remove-CimInstance -Verbose -Confirm:$false -ErrorAction SilentlyContinue

Next we are going to delete SCCM’s certificates and GUID file (smscfg.ini) and add the closing brace (“}”) by adding these commands:

 #Remove SCCM'ssmscfgfile(containsGUIDofpreviousinstallation) Remove-Item-Path"$($Env:WinDir)\smscfg.ini"-Force-Confirm:$false-Verbose-ErrorActionSilentlyContinue #Remove SCCMcertificates Remove-Item-Path'HKLM:\Software\Microsoft\SystemCertificates\SMS\Certificates\*'-Force-Confirm:$false-Verbose-ErrorActionSilentlyContinue # Completed Write-Host "All traces of SCCM have been removed"}removeSCCM

And that’s it! I’m sure there’s more traces that SCCM leaves that my script potentially aren’t getting but these are the critical pieces that can prevent you from reinstalling.

Final Script

Here is the final script all put together:

# Attempt to run the SCCM uninstallerfunction uninstallSCCM() { if (Test-Path -Path "$Env:SystemDrive\Windows\ccmsetup\ccmsetup.exe") { # Stop SCCM services Get-Service -Name CcmExec -ErrorAction SilentlyContinue | Stop-Service -Force -Verbose Get-Service -Name ccmsetup -ErrorAction SilentlyContinue | Stop-Service -Force -Verbose # Run the SCCM uninstaller Start-Process -FilePath "$Env:SystemDrive\Windows\ccmsetup\ccmsetup.exe" -ArgumentList '/uninstall' # Wait for the uninstaller to finish do { Start-Sleep -Milliseconds 1000 $Process = (Get-Process ccmsetup -ErrorAction SilentlyContinue) } until ($null -eq $Process) Write-Host "SCCM uninstallation completed" }}# Forcefully remove all traces of SCCM from the computerfunction removeSCCM() { # Stop SCCM services Get-Service -Name CcmExec -ErrorAction SilentlyContinue | Stop-Service -Force -Verbose Get-Service -Name ccmsetup -ErrorAction SilentlyContinue | Stop-Service -Force -Verbose # Take ownership of/delete SCCM's client folder and files $null = takeown /F "$($Env:WinDir)\CCM" /R /A /D Y 2>&1 Remove-Item -Path "$($Env:WinDir)\CCM" -Force -Recurse -Confirm:$false -Verbose -ErrorAction SilentlyContinue # Take ownership of/delete SCCM's setup folder and files $null = takeown /F "$($Env:WinDir)\CCMSetup" /R /A /D Y 2>&1 Remove-Item -Path "$($Env:WinDir)\CCMSetup" -Force -Recurse -Confirm:$false -Verbose -ErrorAction SilentlyContinue # Take ownership of/delete SCCM cache of downloaded packages and applications $null = takeown /F "$($Env:WinDir)\CCMCache" /R /A /D Y 2>&1 Remove-Item -Path "$($Env:WinDir)\CCMCache" -Force -Recurse -Confirm:$false -Verbose -ErrorAction SilentlyContinue # Remove SCCM's smscfg file (contains GUID of previous installation) Remove-Item -Path "$($Env:WinDir)\smscfg.ini" -Force -Confirm:$false -Verbose -ErrorAction SilentlyContinue # Remove SCCM certificates Remove-Item -Path 'HKLM:\Software\Microsoft\SystemCertificates\SMS\Certificates\*' -Force -Confirm:$false -Verbose -ErrorAction SilentlyContinue # Remove CCM registry keys Remove-Item -Path 'HKLM:\SOFTWARE\Microsoft\CCM' -Force -Recurse -Verbose -ErrorAction SilentlyContinue Remove-Item -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\CCM' -Force -Recurse -Confirm:$false -Verbose -ErrorAction SilentlyContinue # Remove SMS registry keys Remove-Item -Path 'HKLM:\SOFTWARE\Microsoft\SMS' -Force -Recurse -Confirm:$false -Verbose -ErrorAction SilentlyContinue Remove-Item -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\SMS' -Force -Recurse -Confirm:$false -Verbose -ErrorAction SilentlyContinue # Remove CCMSetup registry keys Remove-Item -Path 'HKLM:\Software\Microsoft\CCMSetup' -Force -Recurse -Confirm:$false -Verbose -ErrorAction SilentlyContinue Remove-Item -Path 'HKLM:\Software\Wow6432Node\Microsoft\CCMSetup' -Force -Confirm:$false -Recurse -Verbose -ErrorAction SilentlyContinue # Remove CcmExec and ccmsetup services Remove-Item -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\CcmExec' -Force -Recurse -Confirm:$false -Verbose -ErrorAction SilentlyContinue Remove-Item -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\ccmsetup' -Force -Recurse -Confirm:$false -Verbose -ErrorAction SilentlyContinue # Remove SCCM namespaces from WMI repository Get-CimInstance -Query "Select * From __Namespace Where Name='CCM'" -Namespace "root" -ErrorAction SilentlyContinue | Remove-CimInstance -Verbose -Confirm:$false -ErrorAction SilentlyContinue Get-CimInstance -Query "Select * From __Namespace Where Name='CCMVDI'" -Namespace "root" -ErrorAction SilentlyContinue | Remove-CimInstance -Verbose -Confirm:$false -ErrorAction SilentlyContinue Get-CimInstance -Query "Select * From __Namespace Where Name='SmsDm'" -Namespace "root" -ErrorAction SilentlyContinue | Remove-CimInstance -Verbose -Confirm:$false -ErrorAction SilentlyContinue Get-CimInstance -Query "Select * From __Namespace Where Name='sms'" -Namespace "root\cimv2" -ErrorAction SilentlyContinue | Remove-CimInstance -Verbose -Confirm:$false -ErrorAction SilentlyContinue # Completed Write-Host "All traces of SCCM have been removed"}uninstallSCCMremoveSCCM

If you know of more traces that are missing, especially if they stopped you from reinstalling or can cause a problem that perhaps I have yet to encounter, leave a comment and I will add them!

Further Troubleshooting – WMI

If you still can’t reinstall SCCM and you’re sure it has nothing to do with your environment there are a couple “gotchas” that come up a lot with SCCM you should check for. The first one is your computer’s WMI repository. You can verify this with:

winmgmt /verifyrepository

A good result is that your “WMI repository is consistent” like this:

Remove All Traces of Microsoft SCCM w/ PowerShell (By Force) (2)

If it tells you that the WMI repository is inconsistent your WMI repository is broken on that machine. You can attempt a repair with:

winmmgmt /salvagerepositorywinmgmt /verifyrepository

If it came back as consistent now, then the built in tools actually successfully fixed it, nice! If it’s still broken, you did not get lucky and your “good” options are running out. There is another command we can use that resets WMI back to the default state the machine had when it was installed.

Before you try it, I must WARN you, this can sometimes cause problems if you have other applications that have added custom WMI that won’t be there when you reset the WMI repository back to the original default state. It’s not a “safe” command to just run willy-nilly. Specifically:

Rebuilding the WMI repository may result in some third-party products not working until their setup is re-run & their Microsoft Operations Framework re-added back to the repository.

If your only other option is to reimage the machine anyways and you have nothing to lose, YOLO:

winmgmt /resetrepositorywinmgmt /verifyrepository

Hopefully that one got it for you but if not you can get really desperate and try rebuilding the WMI .mof files yourself following this article here.

However, if your WMI is this broken that you are manually trying to repair .mof files, it’s definitely time to seriously consider a reimage at this point. It’s way outside the norm to get this far down the list of WMI troubleshooting and still be having problems when there aren’t a dozen other things wrong with that image on there that haven’t been found yet!

If you’re really determined to fix WMI on that machine there’s more you can do but it’s beyond the scope of this article but at least you know the problem and can do some further research here.

Further Troubleshooting – DISM

DISM stands for “Deployment Image Servicing and Management”. This tool helps you manage your Windows image itself. Windows also has it’s own repository of packages and this tool verifies that they are all there and in the condition they should be.

We can run the DISM command to check our Windows image with PowerShell and make sure it’s “Healthy” like this:

Repair-WindowsImage -Online -CheckHealth
Remove All Traces of Microsoft SCCM w/ PowerShell (By Force) (3)

The other possible results are “Repairable” and “Unrepairable”. It’s pretty unusual to encounter straight up fully “unrepairable” ones, most of the ones you are likely to encounter will show as “Repairable”. If it’s unrepairable then it’s absolutely hilariously broken and essentially needs a straight-up reimage at that point.

The CheckHealth command is a great command and only takes a few seconds to run but it only checks the Windows logs for errors. There’s a more comprehensive scan you can perform if you don’t trust the result you got:

Repair-WindowsImage -Online -ScanHealth

The ScanHealth command actually computes all the hashes and checks every single file in the repository one at a time. It can take several minutes or much longer (15-20+ minutes) than that on old machines still using HDDs instead of solid state storage, but if that one comes back clean it’s a pretty definitive result and it’s time to consider other possibilities.

If it shows repairable you can repair it with:

Repair-WindowsImage -Online -RestoreHealth

If the repair was successful there’s one more step you need to do. All we’ve done with the DISM command is fix the repositories Windows uses to update and replace broken files. Now we need to run the System File Checker tool like this to actually replace the damaged files:

sfc /scannow

There’s definitely some problems you can run into when running DISM (different types of errors) but they’re outside the scope of the article and what to do next can be pretty easily found by putting your error into your favorite search engine. You may also feel free to leave a comment with what you’re seeing! Definitely check out my other PowerShell articles as well for more ideas!

Related Posts:

  • Modify Google Sheets (API) Using PowerShell / Uploading CSV Files
  • Disabling SCCM MDM Coexistence Mode (Unofficial Imperfect Workaround)
  • ServiceNow Automation Using Chrome Extension
Remove All Traces of Microsoft SCCM w/ PowerShell (By Force) (2024)

FAQs

How to uninstall SCCM completely? ›

Uninstall SCCM Client
  1. In your Configuration Manager console, right-click on a device.
  2. Click Right Click Tools > Client Tools > Uninstall SCCM Client.
  3. Confirm that you want to uninstall the client.
Dec 20, 2022

How do I manually remove SCCM management point? ›

The following are the steps you need to follow: Navigate – \Administration\Overview\Site Configuration\Servers and Site System Roles. Right Click on Management Point and Select Remove.

How to remove collection in SCCM? ›

To delete a collection
  1. Set up a connection to the SMS Provider. For more information, see SMS Provider fundamentals.
  2. Get the specific collection instance by using the collection ID provided.
  3. Delete the collection by using the delete method.
Oct 9, 2022

How do I remove inactive devices from SCCM? ›

Two Site Maintenance tasks control stale record deletion in SCCM. Within the Configuration Manager console, these can be accessed under Administration/Site Configuration/Sites – Site Maintenance. Within Site Maintenance, you will see two tasks named: Delete Aged Discovery Data and Delete Inactive Client Discovery Data.

How do I clear SCCM logs? ›

Delete SCCM IIS Logs Files Manually
  1. In the Start a Program section, entrer the following command : Forfiles.exe -p C:\inetpub\logs\LogFiles\W3SVC1 -m *.log -d -30 -c “Cmd.exe /C del @path\”
  2. You can change the number of days if desired (30)
Jul 25, 2022

How to uninstall the software and make sure that it is completely removed? ›

  1. In search on the taskbar, enter Control Panel and select it from the results.
  2. Select Programs > Programs and Features.
  3. Press and hold (or right-click) on the program you want to remove and select Uninstall or Uninstall/Change. Then follow the directions on the screen.

How do I remove software from SCCM software center? ›

Removing Software
  1. Launch Software Center.
  2. Select Installation Status from the left menu. ...
  3. Select the software you wish to uninstall. ...
  4. The software's installation page will open. ...
  5. Once the application has completed uninstalling, you will see the status has changed to show it is no longer installed.
May 21, 2024

How do I disable SCCM? ›

In SCCM Console, go to the Software Library / Application Management / Applications. Select your deployed application. At the bottom select the Deployment tab. Right-click a deployment select Disable.

How do I force delete a component server in SCCM? ›

To force a removal of Component Server, all you need to do is to restart SMS_SITE_COMPONENT_MANAGER service and then come back to SCCM console and refresh the window. Component Server will be gone.

How do I delete a content library in SCCM? ›

Use the content library cleanup command-line tool to remove content that's no longer associated with an object on a distribution point. This type of content is called orphaned content. This tool replaces older versions of similar tools released for past Configuration Manager products.

How do I remove a device from my SCCM database? ›

To delete the device in SCCM, we can just delete computer record from SCCM. Then we should make sure the devices are not exist in AD, if they are still in AD, the devices will be discovered again by SCCM. Or we can configured the device discovery method to exclude the OU with the deleted devices in AD.

How do I remove SCCM from Active Directory? ›

Re: Remove old SCCM configuration from AD

Delete the old objects in the System Management container, don't delete the System Management container, just the objects, including sub-containers. Check DNS for management point records and delete them as well.

How do I remove SCCM from the registry? ›

Perform the following steps to uninstall the SCCM client using ccmclean.exe:
  1. Download the ccmclean.exe tool and copy it over to the target computer.
  2. Run ccmclean.exe as an administrator.
  3. The tool uninstalls the SCCM agent, and at the end, a message box appears: “Your system has been successfully cleaned.”
Feb 28, 2024

How do I manually uninstall SCCM client agent? ›

Uninstall SCCM Client using CCMSetup.exe Command Line
  1. Open a Windows command prompt with the administrator's permission.
  2. Change the folder to the location as mentioned above. Run the following command cd %windir%\ccmsetup.
  3. Run the following command: CCMSetup.exe /uninstall.
Sep 28, 2022

How do I manually uninstall and reinstall SCCM client? ›

You can manually uninstall SCCM client agent by running a simple command – ccmsetup.exe /uninstall.
  1. Run the command prompt as administrator.
  2. Change the path to client agent location – C:\Windows\ccmsetup.
  3. Run the command ccmsetup.exe /uninstall.
  4. Go to C:\Windows\ccmsetup\Logs and open ccmsetup.
Feb 14, 2024

Can you delete ccmcache? ›

The default location is %windir%\ccmcache . To delete the files in the cache folder, choose Delete Files. Don't manually delete files from the ccmcache folder using Windows Explorer or the command line. This action can cause issues with the Configuration Manager client.

What happens if you delete a computer from SCCM? ›

In another scenario, lets say you have client computers in SCCM that have the SCCM client installed and you delete one or more from the SCCM console. The client computer name will show up again in the console but all history (hardware/software info) is lost.

How to uninstall an application through SCCM? ›

Uninstall deployed products with Configuration Manager
  1. Navigate to the folder containing the administrative image for the product you want to uninstall.
  2. Copy the Install <deployment name>. ...
  3. Rename the copy to Uninstall.bat.
  4. Open Uninstall. ...
  5. Activate the uninstall command (the last line of the script) by removing rem.

References

Top Articles
Latest Posts
Article information

Author: Mr. See Jast

Last Updated:

Views: 5986

Rating: 4.4 / 5 (75 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Mr. See Jast

Birthday: 1999-07-30

Address: 8409 Megan Mountain, New Mathew, MT 44997-8193

Phone: +5023589614038

Job: Chief Executive

Hobby: Leather crafting, Flag Football, Candle making, Flying, Poi, Gunsmithing, Swimming

Introduction: My name is Mr. See Jast, I am a open, jolly, gorgeous, courageous, inexpensive, friendly, homely person who loves writing and wants to share my knowledge and understanding with you.