Pass array of CimInstance to CimMethod

Question:

I am working with WMI API through Cim cmdlets. The problem is that I can’t figure out how to pass wmi object to wmi method that accepts array of wmi objects.

Here are method parameters definition:

Path and ResetChildren are simple parameters. They accepts simple values like "/path" and $true respectively. But I have troubles with Permissions parameter.

Here is my code

Execution of this code will result in error:

If you change code

To code

Then error message will also change:

Any ideas how to pass $group to method properly?

Answer:

I had exactly same problem with VisualSVN_Repository::SetSecurity method.

When working with CIM method arguments, you must cast ANY array arguments to [CimInstance[]].

For example, this worked for me:

You must cast array argument to [CimInstance[]] even when it is just a single item.

P.S.: Be careful with Ref array arguments too: you must first cast it to [CimInstance[]] and then to [ref[]]. For example, when calling VisualSVN_Group::Create method:

See also: Tip#5: Passing ref and embedded instances on PowerShell Blog.

Source:

Pass array of CimInstance to CimMethod by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply