Using SCOM 2012 SDK to Retrieve Resource Pools Information

Today I needed to retrieve information about SCOM 2012 resource pools in a PowerShell script, I needed to do this directly via SDK, rather than using the OperationsManager PowerShell module. I couldn’t find any existing scripts via Google, so I spent some time playing with SDK and finally found it. Since it seems no one has mentioned it on the web, here’s how I did it:

Firstly, load the SDK DLL’s. I always use below function:

function Load-SDK()
{
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.EnterpriseManagement.OperationsManager.Common") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.EnterpriseManagement.OperationsManager") | Out-Null
}

Load-SDK

Secondly, connect to the management group. Since I’ll be running this script on a management server, I’m connecting to the management group via the SDK service on the local machine:

$MGConnSetting = New-Object Microsoft.EnterpriseManagement.ManagementGroupConnectionSettings($env:computername)
$MG = New-Object Microsoft.EnterpriseManagement.ManagementGroup($MGConnSetting)

Then, get the management group administration

$Admin = $MG.Administration

Finally, get all resource pools

$ResourcePools = $admin.GetManagementServicePools()

image

In the past, I’ve been using the GetAdministration() method from the management group object to retrieve MG administration object. This time, When I did it, the MG administration object returned from the method does not contain a method for GetManagementServicePools. I then realised the management group contains a property called Administration. the object type is the same as what’s returned from GetAdministration() method.

image

But it looks like the object returned from the “Administration” property contains more members:

image

This is just a quick observation. In the future, I’ll remember to check both places.

2 comments

  1. Hey Tao,

    Good point about the GetAdminstration() method vs Administration property.

    The GetAdministration() method is there for compatibility with the SCOM2007R2 SDK and returns a ManagementGroupAdministration object. It’s actually marked as ‘Obsolete’, so if you call this in C# you get an error saying ‘Please use Administration instead’. In theory, these methods will be completely removed in future versions of the SDK.

    The Administration method is the equivalent property for 2012. It returns the newer IAdministrationManagement interface.

    Many other methods on the ManagementGroup object are deprecated/obsolete in 2012 and moved to other objects. Check out the MSDN docs (http://msdn.microsoft.com/en-us/library/hh326678.aspx) for the ‘current’ methods and properties.

  2. This Load-SDK function just helped me out immensely on a Powershell probe action I was writing. For whatever reason the modules wouldn’t work, but loading the SDK this way did the trick.

Leave a Reply

%d bloggers like this: