Trevor Sullivan's Tech Room

Minding the gap between administration and development

PowerShell: Retrieve List of SCCM Site Codes

Posted by Trevor Sullivan on 2011/07/05


If you’re using System Center Configuration Manager (SCCM / ConfigMgr) 2007, you may want to discover how many SCCM sites you have from Active Directory. Of course, this assumes that you have Active Directory publishing enabled on your primary sites. When enabled, SCCM automatically places site information underneath the CN=System Management,CN=System,DN=mydomain,DC=com container.

Here is some simple PowerShell code to enumerate the site codes of all the SCCM site codes that Active Directory is aware of. This can be useful information for troubleshooting issues related to client location services (eg. a SCCM client that cannot auto-discover its site code).

# (optional) Dynamically retrieve the domain root distinguished name
$DomainRoot = ([adsi]"").distinguishedName

# (optional) Get ADSI object to represent search root
$SearchRoot = [adsi]("LDAP://CN=System Management,CN=System," + $DomainRoot)

# Create an ADSI searcher object, with LDAP-style search filter syntax
$AdSearcher = [adsisearcher]"(objectClass=mSSMSSite)"

# (optional) Set search root of Active Directory searcher to System Management container
$AdSearcher.SearchRoot = $SearchRoot

# Make call to retrieve objects from Active Directory
$SccmSites = $AdSearcher.FindAll()

# Iterate over each mSSMSSite object, and give me the mssmssitecode property
# IMPORTANT: All Active Directory property references must be in lower-case, else ... fail
foreach ($SccmSite in $SccmSites)
{
    $SccmSite.Properties["mssmssitecode"]
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: