Get-CMSite – List all Primary and Secondary Sites

After launching your ConfigMgr 2012 SP1 PowerShell Command Prompt, use the Get-CMSite cmdlet to list all primary and secondary sites in a hierarchy. Since this is a GET verb, everything we do here is query-only, so there is no damage by running any of the examples below.
Examples:

get-cmsite – default arguments, will list all sites as follows:

get-cmsite-sample1

Command Action
get-cmsite | out-gridview Lists all sites to a gridview
get-cmsite | where-object {$_.type -eq 4} List the CAS
get-cmsite | where-object {$_.type -eq 2} List all Primary Sites
get-cmsite | where-object {$_.type -eq 1} List all Secondary Sites
get-cmsite | select-object ServerName, Version | sort-object Servername Lists all sites and version, sorted by servername
get-cmsite | where-object {$_.ReportingSiteCode -eq “AMR” -and $_.Type -eq 1} List all secondary sites assigned to AMR
get-cmsite | select-object ServerName, Version | sort-object Servername | export-csv c:\temp\MySiteServers.csv -notypeinformation Same as previous, but exports to CSV file
get-cmsite | foreach {Get-WmiObject -class Win32_OperatingSystem -computer $_.ServerName | Select-Object __SERVER,@{label=’LastRestart’;expression={$_.ConvertToDateTime($_.LastBootUpTime)}}} Display last bootup time for each server-performs a WQL query on win32_OperatingSystem, so you must have proper rights to remotely connect to each system.

Happy Scripting!
Greg

About Greg Ramsey
Greg Ramsey, Enterprise Mobility MVP, is a Senior Enterprise Architect at Dell, Inc. He has a B.S. in Computer Sciences and Engineering from Ohio State University and has co-authored many books over the years. Greg is a co-founder of the Ohio SMS Users Group and the Central Texas Systems Management User Group. Greg is also a board member of the Northwest System Center User Group and the Director of Communications for the Midwest Management Summit.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: