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

PowerShell and ConfigMgr – List ConfigMgr cmdlets

Now that you’ve learned how to prepare your environment, let’s view all the cmdlets that are currently available for ConfigMgr. From your PowerShell prompt (that already has the ConfigMgr module imported), type the following:

get-command -module ConfigurationManager | out-gridview

This will display all cmdlets in the ConfigurationManager module. As of this writing (ConfigMgr 2012 SP1 Beta) there are 338 cmdlets. Here’s an example for how to get the current count:

get-command -module ConfigurationManager | measure-object

Notice the verb-noun pair for each cmdlet. By using this standard practice, Powershell enables you to 1) think, 2) type, 3) do. The goal is for the admin to use standard verbs to be able to easily leverage PowerShell with different products. (Review the approved verbs for Windows PowerShell). Type get-cm and then press [tab] multiple times to enumerate the ConfigMgr cmdlets. You can also type get-cmmanagementpoint and press [tab] multiple times to display all get commands for ConfigMgr Management Points.

Greg