Remove SCCM Distribution Point Using Powershell Script

In this post we will see how to remove SCCM distribution point using PowerShell script. From past few weeks I have been working on PowerShell a lot. I see it’s very interesting and makes our job easy.

In my previous post I covered the installation of distribution point using powershell script. The script is available for download here. The script is really simple and easy to use. We basically make use of Remove-CMDistributionPoint cmdlet. Therefore using this cmdlet we uninstall distribution point.

In addition to that this cmdlet supports the common parameters such as -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. Most of all ensure you are running SCCM 2012 R2 SP1 and above for this script to work.

I have tested this script on Configuration Manager current branch versions 1511, 1606, 1610, 1702, 1706, 1710, 1802, 1806, 1810, 1902, 1910, 2002. The script to uninstall SCCM distribution point is available for download here.

Remove SCCM Distribution Point Using Powershell Script

This script removes a distribution point by using a site code and site system role. So before you use this script, specify the following values in the script.

$SiteCode – Provide your site code (3 alphanumeric characters).

$DistributionPoint – Specify the server FQDN from where you want to uninstall DP role.

Script Explanation

Remove-CMDistributionPoint – Removes a distribution point.

-Force – Runs the command without asking for user confirmation.

Copy the below script into a notepad and save it as filename.ps1 extension.

< #.SYNOPSIS
Remove Distribution Point role using PowerShell Script

.DESCRIPTION 
This scripts lets you uninstall SCCM Distribution Point

.PARAMETER DistributionPoint
This is the server name from which you would be uninstalling Distribution Point role.

.PARAMETER SiteCode
This is 3 letter site code.

.NOTES
Version: 1.0
Published Date: 10-Dec-2016
Updated Date: 21-Apr-2020
Author: Prajwal Desai
Website: https://www.prajwaldesai.com
#>

#Load the Configuration Manager Module
import-module ($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5) + '\ConfigurationManager.psd1')
$Drive = Get-PSDrive -PSProvider CMSite
CD "$($Drive):"

#Site Code and Distribution Point Server Information
$SiteCode = 'IND'
$DistributionPoint = 'WIN2016.PRAJWAL.LOCAL'

#Check if the DP server is alive
Test-Connection -ComputerName $DistributionPoint -quiet

#Remove Distribution Point Role
write-host -ForegroundColor Green "The Distribution Point Role is being uninstalled on $DistributionPoint"
Remove-CMDistributionPoint -Force -SiteCode $SiteCode -SiteSystemServerName $DistributionPoint

Open the script using Powershell ISE. Substitute site code and distribution point values in the script. Save the script and then run the script. If the distribution point server is online, you will see result as True. In the next step you see the distribution point role is uninstalled from the server.

Remove SCCM Distribution Point Using Powershell Script
Remove SCCM Distribution Point Using Powershell Script

If you have any questions regarding this script, mention it in the comments.

9 Comments

  1. Avatar photo Richard Crews says:

    Final product for using a CSV with “Computer” as a header:

    #Site Code and Distribution Point Server Information

    $SiteCode = ‘IND’

    $CSVin = “C:\Scripts\Remove-CMDistributionPoint\RemoteDP.csv”

    #Get the content of the CSV file

    $Computers = Import-Csv $CSVin

    #Loop through each Device and perform actions

    Foreach ($Computer in $Computers) {

      #Check if the DP server is alive

      Test-Connection -ComputerName $Computer -quiet

      #Remove Distribution Point Role

      write-host -ForegroundColor Green “The Distribution Point Role is being uninstalled on $Computer”

       

    1. Avatar photo Richard Crews says:

      This wasn’t reliable for me but after a little tweak this ran through 220 DP role removals:

      <#

      .SYNOPSIS

      Remove Distribution Point role using PowerShell Script

      .DESCRIPTION 

      This scripts lets you uninstall SCCM Distribution Point

      .PARAMETER DistributionPoint

      This is the server name from which you would be uninstalling Distribution Point role.

      .PARAMETER SiteCode

      This is 3 letter site code.

      .NOTES

      Version: 1.0

      Published Date: 10-Dec-2016

      Updated Date: 21-Apr-2020

      Author: Prajwal Desai

      Website: https://www.prajwaldesai.com

      #>

      #Load the Configuration Manager Module

      import-module ($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5) + ‘\ConfigurationManager.psd1’)

      $Drive = Get-PSDrive -PSProvider CMSite

      CD “$($Drive):”

      #Site Code and Distribution Point Server Information

      $SiteCode = ‘ABC’

      $CSVin = “path to csv file”

      #Get the content of the CSV file

      $Computers = Get-Content -Path $CSVin

      #Loop through each Device and perform actions

      Foreach ($Name in $Computers){

        #Check if the DP server is alive

        Test-Connection -ComputerName $Name -quiet

        #Remove Distribution Point Role

        write-host -ForegroundColor Green “The Distribution Point Role is being uninstalled on $Name”

        Remove-CMDistributionPoint -Force -SiteCode $SiteCode -SiteSystemServerName $Name

  2. Avatar photo Richard Crews says:

    I’ve been referencing your site for years now. This is a great help! I am a PS noob but I hope to get this working with a CSV because I have to remove the DP role from over 200 workstations.

    BTW, there is a space after the lesser than sign. I changed:

    < #.SYNOPSIS

    to:

    <#

    .SYNOPSIS

  3. Avatar photo Maheswara reddy kesu says:

    How to remove site system?

    1. Avatar photo Richard Crews says:

      This question is in reference to the Site System role that SCCM removes on its own after a period of time.You are not able to remove it by design.

      1. Avatar photo Harald Bäs-Fischlmair says:

        You may remove the Site System itself!
        Remove-CMSiteSystemServer -SiteSystemServerName $dp -SiteCode $site -Force -ErrorAction SilentlyContinue

        The only thing missing is the maintainenance of the orphaned Library on the uninstalled DP ..

        I think about creating an CMScript an run the CMScript for deleteing the share and folder of the Content Library after uninstalling the dp role …

  4. Avatar photo Ahmed Essam says:

    What about if i want to remove about 240 DP

  5. Avatar photo Ayrton Walter says:

    Hello Prajwal!

    What if we are trying to discontinue/uninstall permanently offline DPs?
    Is the same procedure applicable?

    Regards

Leave a Reply

Your email address will not be published. Required fields are marked *