PowerShell ISE Add-On to connect to ConfigMgr (Connect-ConfigMgr)

01/04/2015

2 minutes to read

In this article

Man, I’ve been on a PowerShell rampage lately!

It always drove me crazy loading the PowerShell Module for ConfigMgr. First, you had to find the path of the AdminConsole\bin directory and then remember the name of the psd1 module file. Finally, you had to remember the site code of the site you normally work with.

This post outlines a custom PowerShell ISE Add-On I’ve created to quickly load the ConfigMgr PowerShell module and connect to your console default SMS Provider location.

The first thing you’ll need to do is create a custom PowerShell ISE profile (if you don’t already use one)

Browse to %UserProfile%\Documents and look for a WindowsPowerShell directory. If it doesn’t exist, create it. Then, look for a file called Microsoft.PowerShellISE_profile.ps1 (again if it doesn’t exist, create it). This file is automatically loaded when the ISE starts up, and is really handy for auto-loading any common functions.

Now edit the file in either the PowerShell ISE or Notepad.exe and paste in my script. If you’ve already created and customized your profile in the past, just add my script to the bottom of your profile file.

001002003004005006007008009010011012013014015016017018019020021022023024025026027028029030031032033034035036037038039040041042 ## ADDS A Connect-ConfigMgr ITEM TO THE ISE ADD-ONS MENU #### Created by Matt Shadbolt - http://blogs.technet.com/b/ConfigMgrDogs ##Function Connect-ConfigMgr {$CustomError = $null If ($Console64 = Get-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Microsoft\ConfigMgr10\Setup -Name ProductCode -ErrorAction SilentlyContinue) { # 64-bit system $ModulePath = (Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\ConfigMgr10\Setup -Name "UI Installation Directory").'UI Installation Directory' $SiteServerName = (Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\ConfigMgr10\AdminUI\Connection -Name Server).Server $ProviderLocation = gcim -ComputerName $SiteServerName -Namespace root\sms SMS_ProviderLocation -filter "ProviderForLocalSite='True'" $ProviderMachine = $ProviderLocation.Machine $SiteCode = $ProviderLocation.SiteCode Import-Module $ModulePath\bin\ConfigurationManager.psd1 Set-Location $SiteCode":\" }ElseIf ($Console32 = Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\ConfigMgr10\Setup -Name ProductCode -ErrorAction SilentlyContinue) { # 32-bit system $ModulePath = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\ConfigMgr10\Setup -Name "UI Installation Directory").'UI Installation Directory' $SiteServerName = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\ConfigMgr10\AdminUI\Connection -Name Server).Server $ProviderLocation = gcim -ComputerName $SiteServerName -Namespace root\sms SMS_ProviderLocation -filter "ProviderForLocalSite='True'" $ProviderMachine = $ProviderLocation.Machine $SiteCode = $ProviderLocation.SiteCode Import-Module $ModulePath\bin\ConfigurationManager.psd1 Set-Location $SiteCode":\" }Else { $CustomError = [String]"Error: The required registry keys cannot be found. Please ensure the console has been installed on this computer" Throw $CustomError }}$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Connect-ConfigMgr", { Connect-ConfigMgr},"ALT+F1") | out-Null

Save the file and re-open the ISE. You’ll now have a Connect-ConfigMgr option in the Add-Ons menu. You can either select this option, or just press Alt+F1 from the ISE and your console will connect to your console configured SMS Provider.

I've also added this script to the TechNet Gallery - https://gallery.technet.microsoft.com/PowerShell-ISE-Add-On-to-4790e37b

I hope this significantly speeds up your ConfigMgr work in the PowerShell ISE!

Matt