forked from DeploymentResearch/DRFiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRemove-ConfigMgrClientCompletely.ps1
48 lines (39 loc) · 2.31 KB
/
Remove-ConfigMgrClientCompletely.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Uninstall ConfigMgr agent via ccmsetup.exe
.\ccmsetup.exe /uninstall
# Stop WMI Service
$ServiceName = "winmgmt"
$Service = Get-Service -Name $ServiceName
if ($Service.Status -eq "Running"){
Stop-Service $ServiceName -Force
Write-Host "Stopping $ServiceName service"
" ---------------------- "
" Service is now stopped"
}
if ($Service.Status -eq "stopped"){
Write-Host "$ServiceName service is already stopped"
}
# Remove ConfigMgr agent services
sc delete ccmsetup
sc delete ccmexec
sc delete cmrcservice
sc delete smstsmgr
If (Test-Path -Path 'HKLM:\SYSTEM\CurrentControlSet\services\Ccmsetup'){ Remove-Item 'HKLM:\SYSTEM\CurrentControlSet\services\Ccmsetup' -Recurse }
If (Test-Path -Path 'HKLM:\SYSTEM\CurrentControlSet\services\CcmExec'){ Remove-Item 'HKLM:\SYSTEM\CurrentControlSet\services\CcmExec' -Recurse }
If (Test-Path -Path 'HKLM:\SYSTEM\CurrentControlSet\services\smstsmgr'){ Remove-Item 'HKLM:\SYSTEM\CurrentControlSet\services\smstsmgr' -Recurse }
If (Test-Path -Path 'HKLM:\SYSTEM\CurrentControlSet\services\CmRcService'){ Remove-Item 'HKLM:\SYSTEM\CurrentControlSet\services\CmRcService' -Recurse }
# Remove ConfigMgr agent directories
If (Test-Path "$env:windir\ccm") { Remove-Item -Path "$env:windir\ccm" -Recurse }
If (Test-Path "$env:windir\ccmsetup") { Remove-Item -Path "$env:windir\ccmsetup" -Recurse }
If (Test-Path "$env:windir\ccmcache") { Remove-Item -Path "$env:windir\ccmcache" -Recurse }
# Remove other ConfigMgr agent files
If (Test-Path "%windir%\smscfg.ini") { Remove-Item -Path "$env:windir\smscfg.ini" }
Remove-Item -Path "$env:windir\sms*.mif"
# Remove ConfigMgr agent registry keys
If (Test-Path -Path 'HKLM:\SOFTWARE\Microsoft\CCM'){ Remove-Item 'HKLM:\SOFTWARE\Microsoft\CCM' -Recurse }
If (Test-Path -Path 'HKLM:\SOFTWARE\Microsoft\CCMSetup'){ Remove-Item 'HKLM:\SOFTWARE\Microsoft\CCMSetup' -Recurse }
If (Test-Path -Path 'HKLM:\SOFTWARE\Microsoft\SMS'){ Remove-Item 'HKLM:\SOFTWARE\Microsoft\SMS' -Recurse }
# Remove ConfigMgr agent WMI classes
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
# Remove tasks from task scheduler (taskschd.msc)
# Under Microsoft delete the Configuration Manager folder and any tasks within it