Testing Network Connectivity to SCCM Distribution Points

In this blog post, we'll be exploring a PowerShell script that tests network connectivity to System Center Configuration Manager (SCCM) distribution points. The script is designed to load the SCCM module, retrieve all DPs, and check if they are also management points (MPs). It then tests the relevant ports (HTTP, HTTPS, SMB, and SCCM Notification) for each DP.


Prerequisites


Before running this script, you'll need to have:


* PowerShell version 5.1 or higher

* The SCCM module installed


Here's what you can expect from this script:


* It connects to the site drive using the `CMSite` provider * It retrieves all DPs and MPs, and stores them in a HashSet for instant lookup * For each DP, it determines which ports to test based on its role (DP or MP) * It tests the relevant ports using an optimized socket test * It reports the results, including any connectivity issues The Script Here's the full script, broken down into logical sections:


Initialization


# --- Initialization ---
Clear-Host
$ErrorActionPreference = "Stop"

# Load Configuration Manager Module safely
if (-not (Get-Module -Name ConfigurationManager)) {
    $AdminUIPath = $ENV:SMS_ADMIN_UI_PATH
    if ($null -eq $AdminUIPath) {
        Throw "SMS_ADMIN_UI_PATH environment variable not found. Is the SCCM Console installed?"
    }
    Import-Module "$AdminUIPath\..\ConfigurationManager.psd1" -Force
}

# Connect to Site Drive
if (-not (Get-PSDrive -Name $SiteCode -PSProvider CMSite -ErrorAction SilentlyContinue)) {
    Write-Host "Connecting to site $SiteCode..." -ForegroundColor Cyan
    New-PSDrive -Name $SiteCode -PSProvider CMSite -Root $ProviderMachineName | Out-Null
}
Set-Location "$($SiteCode):\"

Data Gathering


# --- Data Gathering ---
Write-Host "Gathering Site Roles..." -ForegroundColor Cyan

# Get all DPs
$DistributionPoints = Get-CMDistributionPoint | Select-Object -ExpandProperty NetworkOSPath
# Get all MPs (network paths) and store in a HashSet for instant lookup
$ManagementPoints   = Get-CMManagementPoint | Select-Object -ExpandProperty NetworkOSPath
$MPSet = [System.Collections.Generic.HashSet[string]]::new([string[]]$ManagementPoints, [System.StringComparer]::OrdinalIgnoreCase)

Main Processing


# --- Main Processing ---
$Results = foreach ($rawDPPath in $DistributionPoints) {
    $ComputerName = $rawDPPath -replace "\\", ""
    
    Write-Host "Processing: $ComputerName" -ForegroundColor Yellow

    # Determine Ports based on Roles
    if ($MPSet.Contains($rawDPPath)) {
        # DP is also an MP: Add port 10123 (Notification Server)
        $Ports = @(80, 135, 139, 443, 445, 10123)
    } else {
        # Standard DP ports
        $Ports = @(80, 135, 139, 443, 445)
    }

    # Test Ports Loop
    foreach ($Port in $Ports) {
        $Status = "Failed"
        
        # --- Optimized Socket Test ---
        try {
            $TcpClient = New-Object System.Net.Sockets.TcpClient
            $ConnectTask = $TcpClient.ConnectAsync($ComputerName, $Port)
            $Signaled = $ConnectTask.Wait($TimeoutMilliseconds)
            
            if ($Signaled -and $TcpClient.Connected) {
                $Status = "Successful"
                Write-Host "    Port $Port : OK" -ForegroundColor Green
            } else {
                Write-Host "    Port $Port : FAIL" -ForegroundColor Red
            }
        }
        catch {
             Write-Host "    Port $Port : ERROR ($($_.Exception.Message))" -ForegroundColor Red
        }
        finally {
            # CRITICAL: Always close the socket to prevent resource exhaustion
            if ($TcpClient) { $TcpClient.Dispose() }
        }

        # Output Object
        [PSCustomObject]@{
            DistributionPoint = $ComputerName
            Port              = $Port
            Result            = $Status
            Role              = if ($MPSet.Contains($rawDPPath)) { "DP + MP" } else { "DP" }
        }
    }
}

Reporting


# --- Reporting ---
Write-Host "`n--- Summary ---`n"

$FailedChecks = $Results | Where-Object { $_.Result -ne "Successful" }

if ($FailedChecks) {
    Write-Warning "Connectivity issues detected on $($FailedChecks.Count) checks:"
    $FailedChecks | Format-Table -AutoSize
} else {
    Write-Host "All port checks completed successfully!" -ForegroundColor Green
}

Usage Examples


To use this script, simply replace the placeholders with your own values:

* `$SiteCode`: the code of your SCCM site

* `$ProviderMachineName`: the name of the machine that hosts the site drive


Run the script in PowerShell and follow the prompts to test network connectivity to your SCCM distribution points.


Conclusion

 In this blog post, we've explored a PowerShell script that tests network connectivity to SCCM distribution points. This script can be useful for automating network checks and identifying potential issues with connectivity to DPs and MPs.


As always the full script can be got on my github