-
Notifications
You must be signed in to change notification settings - Fork 127
/
DPCleanup.ps1
36 lines (32 loc) · 1.69 KB
/
DPCleanup.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
<#
.SYNOPSIS
ConfigMgr Distribution Point Cleanup
.DESCRIPTION
This script will cleanup the remnants of a distribution point after it has been deleted in Configuration Manager. This is sometimes necessary when needing to repush a distribution point to the same server.
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2017 v5.4.142
Created on: 6/12/2020 2:01 PM
Created by: Mick Pletcher
Filename: DPCleanup.ps1
===========================================================================
#>
[CmdletBinding()]
param ()
#Uninstall ConfigMgr Client
If ((Test-Path ($env:windir + '\ccmsetup\ccmsetup.exe')) -eq $true) {
Start-Process ($env:windir + '\ccmsetup\ccmsetup.exe') -ArgumentList "/uninstall" -Wait
}
#Retrieve the path to the distribution point directories
If ((Test-Path 'REGISTRY::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SMS\DP') -eq $true) {
$ContentLibraryPath = ((Get-ItemProperty -Path 'REGISTRY::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SMS\DP').ContentLibraryPath).split('\')[0] + '\'
} else {
Write-Host 'Cannot find path to distribution point content'
Exit 1
}
#Delete the distribution point directories
(Get-ChildItem -Path $ContentLibraryPath | Where-Object {($_.Name -like 'SMS*') -or ($_.Name -like 'SCCM*')}) | ForEach-Object {Remove-item -Path $_.FullName -Recurse -Force}
#Delete registry keys associated with ConfigMgr
If ((Test-Path "REGISTRY::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SMS") -eq $true) {
Remove-Item -Path "REGISTRY::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SMS" -Recurse -Force -ErrorAction SilentlyContinue
}