PowerShell - SCOM PropertyBag, How to check if already added?

2.4k Views Asked by At

I want to add values to a PropertyBag.

How is it possible to check if the value is already in the PropertyBag?

I know one can use an array, list, etc. But how can I use the $bag/$api object to do this check?

$api = New-Object -comObject “MOM.ScriptAPI”
$bag = $api.CreatePropertyBag()
$bag.AddValue("TestValue1","1234")

I'm searching for something like this:

if($bag -match "TestValue1")
{"In the Bag!"}

But, unfortunately, it's not working.

1

There are 1 best solutions below

0
Norman Skinner On

I do not have SCOM on a server I can access, but could you do the following to get the bag contents and check against it?

$api = New-Object -comObject “MOM.ScriptAPI”
$bag = $api.CreatePropertyBag()
$bagContents = $api.Return($bag)