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

ConfigMgr and PowerShell-Preparing Your Environment – Part II

Yesterday, we walked through the process of launching PowerShell from the ConfigMgr console as well as importing the ConfigMgr module from the PowerShell command line.  Here’s a little additional information so that you can create a shortcut to easily launch to that PowerShell command prompt for ConfigMgr, and automatically connect to the desired site.

First, create a file called C:\PowerShell\LaunchCM.ps1 with the following contents:

import-module 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1' -force
if ((get-psdrive LAB -erroraction SilentlyContinue | measure).Count -ne 1) {
new-psdrive -Name "LAB" -PSProvider "AdminUI.PS.Provider\CMSite" -Root "MyLABServer.Ramseyg.com"
}
cd LAB:

Replace “LAB” with the proper site code, and “MyLabServer.Ramseyg.Com” with the FQDN to the site (or SMS provider).

Next create a new shortcut with the following target:

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -noexit -executionpolicy Unrestricted -file C:\PowerShell\LaunchCM.ps1

This will launch an unrestricted PowerShell command prompt, loaded to your desired ConfigMgr site. As an added bonus, you can modify the shortcut properties (click the Advanced button) to configure the shortcut to always run as administrator.

Happy Scripting!

Greg