SCOM MP Authoring - Get SCOM ID (Groups and Servers)

I would like to write a management pack that will allow me to retrieve the ScomID of a SCOM group or server object. Therefore, script needs to execute on the SCOM Management server (rather than the client) and the object name to be passed to whatever function/script necessary to query SCOM. Where would you start with something like this?

Functions for retrieving ScomID

Function GetSCOMComputerID{
[cmdletbinding()]
param
(
[parameter(Mandatory,ValueFromPipeline)]
[string]$ComputerFQDN
)
$SCOMComputerID = (Get-SCOMClassInstance -Name $ComputerFQDN).ID
return [string]$SCOMComputerID
}

Function GetSCOMGroupID{
param
(
[parameter(Mandatory,ValueFromPipeline)]
[string]$GroupName
)
$SCOMGroupID = (Get-SCOMGroup $GroupName).ID
return [string] $SCOMGroupID
}
2 Likes

in my self maintenance MP, there’s an agent task to get workflow ID. what you are trying to do is very similar to that task. please take a look and hopefully it will give you some ideas. you can input these script parameters as task override parameters.

1 Like

that’s covered in the second part of the workshop guide (the homework part) :). please let us know if you need help with that.

1 Like

Here's a slightly different approach:

The ID of the target object is available to any agent task, so write a task to simply return the ID. This task would be available for any SCOM object. To use it, locate the object in the SCOM console (via search, or a view) and run the task.

To create this task using the SCOM console:

SCOM Console > Authoring > Management Pack Objects > Tasks

Task pane > Create a New Task

Task Type = Agent Tasks / Command Line

Choose an MP

<Next>

Task name = Get SCOM ID

Task target = Object, System Library (select “View all targets” and search for “object”)

<Next>

Full path to file = cmd.exe

Parameters = /C “echo $Target/Id$”

<Create>

You can now run the task like this:

Exporting the management pack and viewing the resulting XML may give you some ideas of how to use parameters in your own task.

And lastly, don’t forget that the ID of the object is also in the Squared Up URL for an object drilldown, which is a very easy way of finding the ID.

2 Likes

Do you plan to use this script/functions in a console task?

Yes the idea is to be able to execute the functions as console tasks

Thank you Tao - I’ll have a look. Writing a management pack as per the demo today in terms of running a script on the client looks straight forward. The bit I need to research is how you can run a task to execute on the SCOM server but pass the parameter of the object in scope/highlighted

This is exactly what I wanted to achieve - thank you Richard