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

email

Written by , Posted .
  • DVS

    I run the New-PSDrive command with all my stuff and I get the error “new-psdrive : Object reference not set to an instance of an object”

    What does this mean? I’m trying it on my workstation not the System Center Server.

  • sonam rastogi

    hi, i am also getting the same error : Object reference not set to an instance of an object while trying new-psdrive.

    did you get the solution, please let me know.