ConfigMgr and PowerShell-Preparing Your Environment – Part II

Yesterday, we walked through the process of launching PowerShell from the ConfigMgr console as well as importing the ConfigMgr module from the PowerShell command line.  Here’s a little additional information so that you can create a shortcut to easily launch to that PowerShell command prompt for ConfigMgr, and automatically connect to the desired site.

First, create a file called C:\PowerShell\LaunchCM.ps1 with the following contents:

import-module 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1' -force
if ((get-psdrive LAB -erroraction SilentlyContinue | measure).Count -ne 1) {
new-psdrive -Name "LAB" -PSProvider "AdminUI.PS.Provider\CMSite" -Root "MyLABServer.Ramseyg.com"
}
cd LAB:

Replace “LAB” with the proper site code, and “MyLabServer.Ramseyg.Com” with the FQDN to the site (or SMS provider).

Next create a new shortcut with the following target:

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -noexit -executionpolicy Unrestricted -file C:\PowerShell\LaunchCM.ps1

This will launch an unrestricted PowerShell command prompt, loaded to your desired ConfigMgr site. As an added bonus, you can modify the shortcut properties (click the Advanced button) to configure the shortcut to always run as administrator.

Happy Scripting!

Greg

About Greg Ramsey
Greg Ramsey is a systems engineer specializing in global systems management for Dell IT. He has a B.S. in Computer Sciences and Engineering from the Ohio State University and is a Microsoft Most Valuable Professional (MVP) for Microsoft System Center Configuration Manager. Greg coauthored SMS 2003 Recipes: A Problem-Solution Approach (Apress, 2006), Microsoft System Center Configuration Manager Unleashed (Sams, 2009), Microsoft System Center 2012 Configuration Manager Unleashed (Sams, 2012), and Microsoft System Center 2012 Configuration Manager: Administration Cookbook (Packt Publishing, 2012), and Microsoft System Center 2012 Configuration Manager R2 Unleashed (Sams, 2012). Greg is cofounder of the Ohio SMS Users Group, and the Central Texas Systems Management User Group.

4 Responses to ConfigMgr and PowerShell-Preparing Your Environment – Part II

  1. Pingback: PowerShell and ConfigMgr – List ConfigMgr cmdlets « Greg's Systems Management Blog

  2. Pingback: Get-CMSite « Greg's Systems Management Blog

  3. Pingback: How To: List Packages that are Configured to use a Package Share in ConfigMgr 2012 « Greg's Systems Management Blog

  4. Pingback: ConfigMgr and PowerShell ISE (x86) | Mike's Tech Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: