Loading automatically the ConfigMgr 2012 SP1 PowerShell module

If you want to load the Configuration Manager 2012 SP1 PowerShell module, you can do it from the upper menu of the admin console:

To discover what it does exactly, I did:

gwmi win32_process | fl commandline

And obtained the following:
commandline : “C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe”
-noExit -ExecutionPolicy AllSigned -Command “Import-Module
‘C:\Program Files (x86)\Microsoft Configuration
Manager\AdminConsole\bin\ConfigurationManager.psd1’; CD MYSITECODE:” |
Invoke-Expression

The above command line triggers an addtional prompt about code signing:

What else do we know about the above command line? There are actually 2 caveats:

  • The module can only be loaded from a 32bit powershell console. As you can see, if you try to load it under a 64bit powershell console, you’ll have:

    Import-Module : PowerShell is not supported in 64-bit version. Run PowerShell in x86 version and import the module
  • All the ConfigMgr cmdlets should be executed when you’re on the provider drive, otherwise you may encounter the following message:
    This command cannot be run from the current drive. To run this command you must first connect to a Configuration Manager drive.

I usually launch the powershell console from the taskbar, which is 64bit console and thus the wrong console 😦

What can I do? Well, I propose to launch it using the current user powershell profile named $profile as it’s shared between the 64 and 32bit consoles.

  • First step: I created a profile
  • notepad $profile

    (NB: the path must exist before creating the file)

  • Second step: Change the execution policy to “RemoteSigned” because my current profile isn’t digitally signed.
  • Third step: Copy/paste the following code in the “${env:userprofile}\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1”
# Requires -Version 3.0            
            
$ConfigMgrConsoleCode = @'
try{
    $ConfigMgrPath = Split-Path -Path "${Env:SMS_ADMIN_UI_PATH}" -ErrorAction Stop
} catch {
    Write-Warning -Message "Failed to find ConfigMgr environment variable because $($_.Exception.Message)"
}
if ($ConfigMgrPath) {
    $ConfigMgrModuleLoaded = $false
    $ConfigMgrConsoleFile = Join-Path -Path $ConfigMgrPath -ChildPath "ConfigurationManager.psd1"
    if (Test-Path -Path $ConfigMgrConsoleFile) {
        try {
            Write-Verbose -Message "Loading ConfigMgr module from $ConfigMgrConsoleFile" -Verbose
            Import-Module $ConfigMgrConsoleFile -ErrorAction Stop
            $ConfigMgrModuleLoaded = $true
        } catch {
            Write-Warning -Message "Failed to load ConfigMgr 2012 SP1 module because $($_.Exception.Message)"
        }
        if ($ConfigMgrModuleLoaded) {
            # Change the title of the console
            $Host.UI.RawUI.WindowTitle = "$($Host.UI.RawUI.WindowTitle) 32bit (running as $($env:USERNAME))"
            try {
                $ConfigMgrPSProvider = Get-PSDrive -PSProvider CMSite -ErrorAction Stop
            } catch {
                Write-Warning -Message "Failed to find the PSProvider for ConfigMgr 2012 SP1"    
            }
            if ($ConfigMgrPSProvider) {
	        'Your ConfigMgr Site server is: {0}' -f ($ConfigMgrPSProvider).SiteServer
                'Your ConfigMgr Site   code is: {0}' -f ($ConfigMgrPSProvider).SiteCode
                cd "$($ConfigMgrPSProvider.SiteCode):\"
                try {
                    Update-Help -Module ConfigurationManager -Force -ErrorAction Stop
                } catch {
                    Write-Warning -Message "Failed to update the help of the ConfigurationManager module because $($_.Exception.Message)"
                }
            }
        }
    } else {
        Write-Warning -Message "ConfigMgr 2012 SP1 module not found"
    }
}
'@            
if ($pshome -eq "$($env:windir)\SysWOW64\WindowsPowerShell\v1.0") {            
    Write-Verbose -Message "Trying to load ConfigMgr 2012 SP1 module if appropriate" -Verbose            
    Invoke-Expression -Command $ConfigMgrConsoleCode            
} else {            
    Write-Verbose -Message "Launching a 32bit powershell console to load ConfigMgr 2012 SP1 module" -Verbose            
    Start-Process -FilePath "$($env:windir)\SysWOW64\WindowsPowerShell\v1.0\PowerShell.exe" -Verb Runas             
}

Now, whenever I launch the 64bit powershell console from the taskbar, elevated or not, I’ve got a second powershell 32bit console poping up that loads automatically the ConfigMgr 2012 SP1 PowerShell module, and as a bonus…

…it updates automatically the help associated with the module:

Now, I’m feeling more confortable to work with it 😎 as old habits die hard.

Advertisements

3 thoughts on “Loading automatically the ConfigMgr 2012 SP1 PowerShell module

  1. VMware Certified Advanced Professional 6 (Desktop and Mobility Deployment) – The industry-recognized VCAP6-DTM Deploy certification validates that you know how to deploy and optimize VMware Horizon 6 (with View) environments. It proves that you have the understanding and skills essential to leverage best practices to provide a scalable and reliable Business Mobility platform for your business. Some of the subjects include: Configuring and managing Horizon View components, configuring cloud pod archituecture, configuring Group Policy settings related to Horizon View, Configuring and optimizing desktop images for Horizon View & Mirage, Configuring and managing App Volumes AppStacks, Configuring desktop pools, Configuring and deploying ThinApp packaged applications, Configuring VMWare Identity Manager, etc.Sebastian’s take on the VCAP6 examination: “In my personal opinion VCAP6 exam is way better experience in comparison with VCAP5, the new examination appears exactly like VMware HOL. The user interface is straightforward, questions are well organized on the right side of the screen, and can be concealed aside or restored when desired. My bits of advice to the questions window: if you opt to make it floating, you should know how to restore it back. I ended up shifting it all around merely because I fail to remember how to recover it back. The two arrows that appeared like buttons on top were used to dock the window to right or left. Fonts can be resized, which from my opinion was much better than scrolling down and up the question. The response speed of the entire interface was so considerably faster than VCAP5.5, and there was no lagging time period experienced when changing from window to window. Something to keep in mind: BACKSPACE key is not working! I do believe this is beneficial since you don’t reload your examination window in error, nonetheless, it could be troublesome occasionally whenever you type some thing erroneously and you need to select and press Del to remove. The Desktop and shortcuts were sorted very nicely, and required programs like browser or Mirage console are easily launched. You will find a decent user interface for Remote Desktop Manager where you can find all required RDP connection to servers or desktops with no need to type username and password. The web browser had all the links in the Favorite Bar. At the time I’m writing this, there’s no additional Thirty minute extension for Non-Native English speaker at No-Native English country, which is a bummer. You will find 39 question to answer within the 3 hours period, which can be actually quite hard for non-native English speakers like me. Some questions take time to finish, making it better to drop the questions that you cannot answer, and finish those you can. After the 39 questions, you can return to the uncompleted questions when you still have time. Never squander too much time on one single question! The examination blue print can be found on my weblog at Szumigalski.com. It is well-organized and following it for the examination preparation should help a great deal. Certainly, the most beneficial is if you could have numerous hands on experience! I’m truly very pleased with the examination experience, despite the fact that I passed this time around by small margin, however i know what I missed for the exam, learn from the mistakes and practice harder to get familiar myself with the environment. This qualification will obviously open up your career prospects!”

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