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