1

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
DarkLite1
  • 13,637
  • 40
  • 117
  • 214
  • The relations between SCCM Clients and Distribution Points, with or without the Package share, is made with the Boundary Groups on which the client is located and their associated Site System Servers (DPs). The Package share is populated with content depending on each package, depending if it has the "Copy the content in this package to a package share on a distribution point" checkbox enabled. So what exactly you are trying to match? A client computer with any of its local Ds that have the package share enabled for any package, or for specific packages? – Narcis Feb 15 '17 at 14:03
  • I'm trying to find the share (server name) where the packages are published for a specific computer. Usually this is het server located the closest by for fast installation speeds. – DarkLite1 Feb 15 '17 at 15:10

1 Answers1

1

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.

Narcis
  • 141
  • 6
  • Thank you Narcis, but I'm having some trouble. `Get-PSDrive` doesn't show me the drive, so I can't connect to it. Not even in x86 mode. I have to use `Get-WMIObject` with the `$WMIParams` instead of `Get-CMBoundary` to query for SCCM details. – DarkLite1 Feb 16 '17 at 08:01
  • That is because you need to load the SCCM PS Module, which the script should do automatically (if you have the SCCM Console installed). Anyway, you can replace the Get-CMBoundary line with this: $ClientBoundary = Get-WmiObject -Namespace "ROOT\SMS\site_$site" -Query "select * from SMS_Boundary" | Where {$_.DisplayName -like "*$ClientADSite"} – Narcis Feb 16 '17 at 08:09
  • Thx again, but there's no match. It seems like `$ClientObject.ADSiteName = BEL-Brussels-0022` and `$ClientBoundary.DisplayName = BEL/Brussels/Street Nr`, with the latter having multiple duplicates. – DarkLite1 Feb 16 '17 at 08:32
  • So you have defined manually the boundaries in your environment. Then, you can try to go by the boundary value: $ClientBoundary = Get-WmiObject -Namespace "ROOT\SMS\site_$site" -Query "select * from SMS_Boundary" | Where {$_.Value -eq "$ClientADSite"} – Narcis Feb 16 '17 at 08:40
  • Thx, really helpful :) Updated the OP with that we have now. The only thing is, sometimes there are multiple entries when multiple subnets are found. Just looking for a way around this, but otherwise, great code! – DarkLite1 Feb 16 '17 at 09:49
  • If you have clients with multiple network interfaces that appear as part of several boundaries, you can pipe the $ClientBoundary line with something like: | Select-Object -First 1. Also, there may be multiple DPs associated with a Boundary Group. – Narcis Feb 16 '17 at 10:40
  • I'm learning a lot here today wirh regards to SCCM. Thx for that! Just found one client with subnet `0.0.0.0` and `192.168.1.10`. That's a bit weird in a company network. – DarkLite1 Feb 16 '17 at 10:43