scom discovery with powersehll variable as propertykey

Hansi 116 Reputation points
2021-06-18T05:23:01.113+00:00

Hello!

I have a script and stored the properties for discovery in an array.

also the values i was created are stored in an array.

now i want to set all the properties like

i = 0
foreach ( $propertyKey in $arrProperties ) {
    $propertyValue = $arrValues[$i]
    $classProperty = '$MP' + "Element[Name='MyClass']/" + $propertyKey + '$'
    $instance.AddProperty("$classProperty", $propertyValue)
    $i += 1

}

But at compilation in VS i get following error:

Incorrect expression specified: $MPElement[Name='MyClass']/. Unable to resolve this expression. Check the expression for errors. (Hints: Check for correct character casing (upper case/lower case), mismatched "$" signs, double quotes("), square brackets "[" or "]"). Here is a sample expression: $MPElement[Name="Windows!Microsoft.Windows.Computer"]/NetworkName$

is it possible to do this?

rg
Hansi

Operations Manager
Operations Manager
A family of System Center products that provide infrastructure monitoring, help ensure the predictable performance and availability of vital applications, and offer comprehensive monitoring for datacenters and cloud, both private and public.
1,413 questions
0 comments No comments
{count} votes