A simple function that allows you to connect to an SCCM Site without the need for using the Configuration Manager GUI or Configuration Manager PowerShell. This allows for automation and automated tasks.

Needs to be run on the Configuration Manager server that has the ConfigurationManager.psd1 file installed in the install path *\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1

Requires the precence of the Environment attribute SMS_ADMIN_UI_PATH and the ConfigurationManager.psd1 file.

UPDATED 27/03/2019

 

v1.1
Improved error handling for the CMSite PSDrive detection after module load.
Improved error handling when attempting to change location to CMSite PSDrive.

 

 

PowerShell
Edit|Remove
<# 
      .SYNOPSIS 
      A function to connect you to an SCCM site to be able to run SCCM comdlets. 
 
      .DESCRIPTION 
      Connects to the specified SCCM Site to allow you to use the ConfigurationManager.psd1 module. 
      Requires the existence of the environment variable 'Env:\SMS_ADMIN_UI_PATH' 
 
      .PARAMETER Site 
      Specify the SCCM Site followed by a colon 
 
      .EXAMPLE 
      Example 1: 
      Connect-SccmSite -Site ABC: 
 
      .INPUTS 
      N/A 
 
      .OUTPUTS 
      N/A 
 
      .NOTES 
      Version :        1.1 
      Author :         Leon Evans 
      Creation Date :  6th March 2019 
      Location : https://gallery.technet.microsoft.com/scriptcenter/site/search?f%5B0%5D.Type=User&f%5B0%5D.Value=Guyver-1 
      Purpose/Change: 
      v1.1 
      Improved error handling for the CMSite PSDrive detection after module load. 
      Improved error handling when attempting to change location to CMSite PSDrive. 
 
      v1.0 
      Original Version. 
  #>