12 June 2020

Legacy Distribution Point Cleanup

This script will clean up the legacy items left over after a distribution point has been deleted in the configuration manager console. This is sometimes necessary if the same server is going to be used to re-push the distribution point back down to it. The script will not proceed if the DP registry keys are not present so that it can find where the distribution point directory exists to be deleted. 

You can download the script from my GitHub site.


 <#  
      .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  
 }  
   

0 comments:

Post a Comment