Scenario 7 – getting a list of primary sites in the Configuration Manager environment
As newbies to the Configuration Manager environment (though not new to Configuration Manager concepts), it is essential that we familiarize ourselves with its site design and implementation. We can list the available primary Configuration Manager sites in the environment by querying local Windows Management Instrumentation (WMI) of the central administrative site (CAS). The following code will demonstrate how to query the CAS WMI to get the list of all the primary sites available in the Configuration Manager environment:
$PrimarySites = @() $SiteCodeList = @() $CentralSiteCode = "ABC" # SCCM site code $CentralSiteProvider = "SCCMCAS" # CAS server name $Sites=Get-WmiObject -Namespace root\sms\site_$CentralSiteCode SMS_Site -Filter "Type=2" -ComputerName $CentralSiteProvider foreach ($site in $Sites) { $SiteCode = $site.SiteCode.ToUpper() $SiteCodeList += $SiteCode $PrimarySites += $site...