Configuration Manager,PowerShell,SCCM,Script,System Center,Windows Server Howto – Connect to Configuration Manager 2012 from Powershell

Howto – Connect to Configuration Manager 2012 from Powershell

Hi, Emil here. Have you ever wonder howto connect to a configuration manager 2012 site from Powershell? Okay, follow the steps below to success:

Requirements:

  • SCCM 2012 Console
  • Powershell 3.0
  • Be a member of SCCM Site Administrators group

1. Install Required Stuff and add you to Sccm Site Admin group.

After you have installed you required stuff like Powershell 3.0 and SCCM 2012 Console on your client or server, you are ready to go to next steps.

2. Start the builtin Windows PowerShell Integrated Scripting Environment (ISE) as a SCCM-Site-administrator.

3. Load the Configuration Manager Module. Type and run following Line:

Import-Module ((Split-Path $env:SMS_ADMIN_UI_PATH) + "\ConfigurationManager.psd1")

4. After you imported the ConfigMgr Module. Now you can go to that psdrive with following line:

Set-Location -Path ((Get-PSDrive -PSProvider CMSite).Name + ":\")

5. Now you are ready to do some rocken roll with your Sccm Site. ex: Try following line, to see all cmdlets for Configuration Manager 2012.

Get-Command -Module ConfigurationManager

Isn’t that cool?

And Here some cool script you can put at beginning of your script, to validate if the configMgr Module is loaded or not. If not loaded – load the module. Else go to cmSite Drive.

# Load the Configuration Manager Module.</pre>
<code> If (!(Get-Module -Name ConfigurationManager))
{
Import-Module ((Split-Path $env:SMS_ADMIN_UI_PATH) + "\ConfigurationManager.psd1")
Set-Location -Path ((Get-PSDrive -PSProvider CMSite).Name + ":\")
}
else
{
Set-Location -Path ((Get-PSDrive -PSProvider CMSite).Name + ":\")
} # End Of script - Load the Configuration Manager Module.</code>


Leave a Reply

Din e-postadress kommer inte publiceras. Obligatoriska fält är märkta *

Related Post