SCOM 2012–Connect to the SDK from PowerShell in an MP

I’ve had a few different scenarios in the past where the need to connect to the SCOM SDK and retrieve data either as part of a monitor or as part of a discovery is necessary.  In most cases, the standard “Import-Module OperationsManager” gets the job done, the SCOM CmdLets are accessible, and whatever workflow I have executing seems to function just fine.  However, recently, I had a customer scenario where this wasn’t working.  The discovery was running on a SCOM management server.  The module was available and functioning outside of a SCOM MP workflow.  For some reason, the Import-Module simply wasn’t working in that specific environment when the PS code was embedded into a management pack.

Troubleshooting wasn’t getting us anywhere so I scanned the existing MPs to see if there was another way that other MPs were loading the OperationsManager module.  I found a few different ways, however, inside of the “Microsoft SystemCenter OperationsManager Summary Dashboard” management pack a connection to the SDK is made like this:

$SCOMPowerShellKey =
“HKLM:\SOFTWARE\Microsoft\System Center Operations Manager\12\Setup\Powershell\V2”
$SCOMModulePath =
Join-Path (Get-ItemProperty $SCOMPowerShellKey).InstallDirectory “OperationsManager”
Import-module $SCOMModulePath

While we didn’t nail down the root cause of the Import-Module failing, this route was successful in connecting to the SDK.

Leave a Reply