Powershell – SCCM Client Sledgehammer aka Reset-CMClient

The following code forces a reset/repair of the SCCM Client on a device. It is very basic, but it succeeds where Install-CMClient fails  even if you force the uninstall before installing

A few prerequisites:

  1. PSExec from https://docs.microsoft.com/en-us/sysinternals/downloads/psexec
  2. Assumption that you are running  a session that has  the ability to PSEXEC to the remote Device AND is already setup to run the SCCMCmdlets

I have commented out the Install Client section , just because, for me it was easier to go into the SCCM Console and push the client when testing and additionally I have two sets of credentials, one for SCCM and one for Device Access.


$SitecodePath  = $Sitecode + ":"

#Uninstall CCM using existing CCMSetup.exe on Device
C:\Utils\PSTools\psexec.exe \\$Computername c:\windows\ccmsetup\ccmsetup.exe /uninstall

$SucessfullUnInstall = $Null
    Write-host "Waiting until SCCM Client is UNINSTALLED"      
         Start-Sleep -Seconds 60
    $SucessfullUnInstall = Get-WinEvent -ComputerName   $Computername -FilterHashTable @{LogName='application';Id = '11724'; ProviderName = 'MsiInstaller';StartTime = $Date} -ErrorAction SilentlyContinue                        
until ($SucessfullUnInstall)

#Now it is uninstalled remove the CCMSetup directory
if (get-item -path \\$Computername\c$\windows\ccmsetup)
Remove-Item   -path \\$Computername\c$\windows\ccmsetup -recurse -force
#Now it is uninstalled remove the CCMCache directory
if (get-item -path \\$Computername\c$\windows\ccmcache -ErrorAction SilentlyContinue)
Remove-Item   -path \\$Computername\c$\windows\ccmcache -recurse -force
#Now it is uninstalled remove the CCM directory
if (get-item -path \\$Computername\c$\windows\ccm)
Remove-Item   -path \\$Computername\c$\windows\ccm -recurse -force

#Now lets push out the client to the device again

set-location $SitecodePath
Install-CMClient -DeviceName $Computername -SiteCode $Sitecode -AlwaysInstallClient $True -ForceReinstall $true -IncludeDomainController $False

$Date = (Get-Date)
$SucessfullInstall = $Null
    Write-host "Waiting until SCCM Client is INSTALLED : Push it out from the SCCM Console to $Computername"      
         Start-Sleep -Seconds 60
    $SucessfullInstall = Get-WinEvent -ComputerName   $Computername -FilterHashTable @{LogName='application';Id = ' 11707'; ProviderName = 'MsiInstaller';StartTime = $Date} -ErrorAction SilentlyContinue                        
until ($SucessfullInstall)





Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.