Find the SCCM Distribution point where the software packages reside

DarkLite1 picture DarkLite1 · Feb 15, 2017 · Viewed 7.2k times · Source

We're trying to find the hostname of the SCCM server that contains the packages/software that can be installed on a client by querying WMI with Get-WMIObject. In other words the server (SCCMPackageServer) that hosts the share with packages when you browse it with explorer like \\SCCMPackageServer\SWD\Packagex.

To get the details of the client is no problem with the following query:

$ComputerName = 'MyWin7Machine'
$WMIParams = @{
    ComputerName = $SCCMServer
    Namespace    = 'root\SMS\site_SITEID'
}
$Client = Get-WmiObject @WMIParams -Query "select * from sms_r_system where Name='$ComputerName'"

Solution (thanks to Narcis):

$Client = Get-WmiObject @WMIParams -Query "SELECT * FROM SMS_R_System WHERE Name='$Computer' AND IPSubnets != ''"
Write-Verbose "Computer '$($Client.Name)', IPSubnets '$($Client.IPSubnets)'"

$Result = Foreach ($S in ($Client.IPSubnets | where {($_ -NE '192.168.1.0') -and ($_ -NE '0.0.0.0') -and 
    ($_ -NE '128.0.0.0') -and ($_ -NE '169.254.0.0') -and ($_ -NE '64.0.0.0')})) {
    Write-Verbose "Check IP '$S'"
    Get-WmiObject @WMIParams -Query "SELECT Displayname, SiteSystems, Value, DefaultSiteCode FROM SMS_Boundary WHERE Value = '$S'"
}

$Result | Select-Object -ExpandProperty SiteSystems -Unique

Answer

Narcis picture Narcis · Feb 16, 2017

Based on your provided details, the bellow script will return the expected list of Distribution Points where packages that may be available to them (for this they must have a deployment) should be present. I have presumed you rely on AD Site Boundaries, based on your code sample provided. Also, you need to run this on a computer with the SMS_Provider role installed.

# Define main variables:
$site = (Get-WmiObject -Namespace "ROOT\SMS" -Query "Select * from SMS_ProviderLocation" | Select-Object -First 1).SiteCode

$SCCMConsoleInstallDir = (Get-ItemProperty "hklm:\software\WOW6432Node\Microsoft\ConfigMgr10\setup")."UI Installation Directory"
Import-Module "$SCCMConsoleInstallDir\bin\ConfigurationManager.psd1"
cd ($site + ":")

$ClientName = "MyWin7Machine"
$ClientObject = Get-WmiObject -Namespace "ROOT\SMS\site_$site" -Query "select * from SMS_R_System" | Where {$_.ADSiteName -ne $null -and $_.Name -eq $ClientName}
$ClientADSite = $ClientObject.ADSiteName

$ClientBoundary = Get-CMBoundary | Where {$_.DisplayName -like "*$ClientADSite"}

$DPs = $ClientBoundary.SiteSystems

Write-Host "The list of Distribution Points associated with the client $ClientName is the following:"
Write-Host "$DPs"

This information is available in the SCCM Console as well, and is configurable. In case you what to follow specific packages, that is a completely different topic and SCCM uses internally Content Location Requests for that. They returns as well a list of locations for the requested package; starting with LOCAL DPs and continuing with FALLBACK ones, depending on the type of CLR.