If you haven’t yet delved into the world of PowerShell for ConfigMgr administration, now is a great time! The beta release of ConfigMgr 2012 SP1 includes a PowerShell module with some 300 cmdlets (get a list of them here) allowing you to peform all manner of functions from the PowerShell environment instead of using the admin console. (If you’ve already cut your teeth on PowerShell with SCCM 2007, then you know this is something to be excited about!)
So if you’re new to PowerShell, how do you access these powerful commands? You need to load the module in your PowerShell environment. This can be done on the fly using the import-module command and specifying the path to the module you want to load. In this case, the module file we need to reference is named ConfigurationManager.psd1 and resides in the ConfigMgr install directory under the AdminConsole\bin folder (ex – D:\Program Files\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1).
ConfigMgr PowerShell Module File
From the command line you simply run the following command to load the module:
import-module D:\Program Files\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1
After a few seconds the module will load and you will have access to all the cmdlets. Keep in mind though that this only loads it for that session, so if you want to have it load any time you launch PowerShell you can add it to your Windows PowerShell profile.
What’s more, if you want to script this so that it will launch no matter where ConfigMgr is installed, try the following command:
import-module ($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5) + '\ConfigurationManager.psd1')
This will use the environment variable ConfigMgr automatically creates pointing to the AdminUI directory to find the path to the PowerShell module.
Now that you have the module loaded, simply type Get-Command -module ConfigurationManager to get a list of all the available modules (also listed here):
List of ConfigMgr PowerShell modules
To get information on the syntax of the cmdlets, simply type Get-Help and the name of the cmdlet (ex – Get-Help Add-CMBoundaryToGroup)
There are a ton of blog posts out there about using PowerShell with ConfigMgr, so I won’t go into more detail at this time. Just throw together a ConfigMgr 2012 SP1 lab with Johan’s Hydration Kit, load the module and start unlocking the “power” in PowerShell! You’ll be glad you did!