Wednesday, September 28, 2016

SCCM: Using Cmdlets from SCCM PowerShell Module

If you want to use PowerShell with SCCM, you can do two things.
  • Load the PowerShell through the SCCM Console (left top corner: Connect via Windows PowerShell)
  • Load the PowerShell module manually
When you use the manual method, the SCCM PS drive should be loaded automatically.
import-module($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5) + '\ConfigurationManager.psd1')

You can verify this with the command Get-PSDrive command
Get-PSDrive -PSProvider CMSite

When the CMSite PowerShell Drive is not available, you can create it yourself and connect to the SCCM site. The only parameter you need is the name of the Site Server which hosts the SMS Provider. This is usually the Primary Site Server.
How to add the CMSite PSDrive manually:
New-PSDrive -Name "SCCM" -PSProvider CMSite -Root "<SCCM_SERVER>"
cd SCCM:
Of course you can use whatever name you want.

More info: (thanks for the csv function!)