找到软件包所在的SCCM分发点

时间:2017-02-15 13:05:30

标签: powershell wmi wmi-query sccm

我们通过查询WMI Get-WMIObject来尝试查找包含可以安装在客户端上的软件包/软件的SCCM服务器的主机名。换句话说,当您使用SCCMPackageServer等资源管理器浏览包时,使用包托管共享的服务器(\\SCCMPackageServer\SWD\Packagex)。

要获取客户端的详细信息,请使用以下查询:

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

解决方案(感谢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

1 个答案:

答案 0 :(得分:1)

根据您提供的详细信息,bellow脚本将返回预期的分发点列表,其中可能存在可用的包(为此必须具有部署)。根据您提供的代码示例,我假设您依赖AD站点边界。此外,您需要在安装了SMS_Provider角色的计算机上运行它。

# 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"

此信息也可在SCCM控制台中获得,并且是可配置的。如果你要遵循特定的包,那是一个完全不同的主题,SCCM使用内部的内容位置请求。它们还返回所请求包的位置列表;从LOCAL DP开始并继续使用FALLBACK,具体取决于CLR的类型。