ConfigMgr and PowerShell-Preparing Your Environment

ConfigMgr 2012 SP1 contains almost everything you need to get started with PowerShell and the new ConfigMgr cmdlets. When you install an Admin console (whether local to the site server or on a remote console), you will see the following option to launch PowerShell with ConfigMgr integration:

Note that you must have the ConfigMgr Admin Console installed on the system where you plan to leverage the new cmdlets. Also, be sure to install the Windows Management Framework 3.0 before you attempt to use PowerShell integration with ConfigMgr.

You can launch a PowerShell Prompt from the image displayed above, and it will automatically load the ConfigMgr module, connected to the site code of the site loaded in the admin console. If you prefer to use the Powershell module without the need to launch from the admin console (recall that  you must have the console installed in order to use the module), perform the following steps:

  1. Open an x86 PowerShell Prompt (when possible, use Run As Administrator)
  2. Run the following command: Import-Module “C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1”  (modify the path as required for your console installation).
  3. Verify the module is enabled by running following command: get-command -module ConfigurationManager This will show all commands available from the ConfigMgr 2012 PowerShell Module (as of this post, there are 338 cmdlets in ConfigMgr 2012 SP1 Beta). If you see the ConfigMgr cmdlets, you’re ready to move to the next level! (If you don’t, be sure you launched the x86 version of PowerShell on x64 systems).
  4. You can then use get-psdrive cmdlet to list the available drives. Notice in the image below that CEN is the site code of my site, and CMSite is the provider.
  5. As shown in the image, simply type cd cen: to navigate to the PowerShell Provider for ConfigMgr site CEN.
  6. Verify you’re connected to the provider by running the following command: get-cmsite This will list all primary and secondary sites in the hierarchy.

As a best practice, always perform admin functions from the central site. However, if you have multiple primary sites (and a CAS), you may need to connect to additional sites (by default, you will automatically connect to the most recently used site server from the Admin Console). Run the following PowerShell command to connect to the site S01:

new-psdrive -Name "S01" -PSProvider "AdminUI.PS.Provider\CMSite" -Root "MySiteServer.FQDN.COM" -Description "S01 Primary Site"

(Replace “S01” with your site code, “MySiteServer.FQDN.COM” with the FQDN to the provider, and “S01 Primary Site” with a description of the site).

Happy Scripting!

Greg

About Greg Ramsey
Greg Ramsey is a Senior Distinguished Engineer for Dell Digital - Services. He has a B.S. in Computer Sciences and Engineering from The Ohio State University and has co-authored many books over the years. Greg is also a board member of the Northwest System Center User Group and the Midwest Management Summit. ​Greg has been a Microsoft Endpoint Manager (ConfigMgr, Intune) MVP for over 18 years.

2 Responses to ConfigMgr and PowerShell-Preparing Your Environment

  1. Pingback: ConfigMgr and PowerShell-Preparing Your Environment – Part II « Greg's Systems Management Blog

  2. Pingback: How To: List Packages that are Configured to use a Package Share in ConfigMgr 2012 « Greg's Systems Management Blog

Leave a comment