Wednesday 20 November 2013

Connecting to ConfigMgr site via PowerShell

Back to ConfigMgr main menu

Back to ConfigMgr & PowerShell menu


There are two ways to connect to your Configuration Manager site via PowerShell.

Method 1: Using the Configuration Manager console




See the blue tab in the top left corner of the console. Click on the down arrow to reveal the menu. Select "Connect via Windows PowerShell".





It takes a few moments but PowerShell loads. See your Site Code in the command prompt.




Type the cmdlet get-cmsite for information about your site.


Method 2: Manually through PowerShell console

All Windows PowerShell cmdlets are coded and stored in a module.  The modules for Windows are available by default in your Windows PowerShell window and you can add more modules.  You add modules to your Windows PowerShell session by importing them using the Import-Module cmdlet.




This is the ConfigMgr module and can be found C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin



Open PowerShell as Administrator (Note that we need the x86 version - the ConfigMgr Admin Console is a 32-bit application) and navigate to that path.

Enter the cmdlet import-module .\ConfigurationManager.psd1 and press enter



Now all the ConfigMgr cmdlets are available

Connect to your site by typing the command

CD P01: (where P01 is your Site Code)


Try get-cmsite again

3 comments:

  1. Hi Gerry,

    I have a odd issue. When I click on "Connect via Windows PowerShell" within the console I get an error says "Configuration manager cmdlets cannot be run because PowerShell 3.0 is not installed, install 3.0 and try again". I'm running the latest version of SCCM 2012 R2 CU1, 5.0.7958.1203. Any idea how I can rectify this issue.
    Thanks,
    Paul

    ReplyDelete
    Replies
    1. Unless your OS is Windows Server 2012 you will not have this version of PowerShell. Download it here
      http://www.microsoft.com/en-ie/download/details.aspx?id=34595

      Delete
    2. Figured it out Gerry. It was actually the WMF version 4.0. As soon as I installed that everything worked like a champ.
      Thanks,
      Paul

      Delete