I work with the WMI API through Cim cmdlets. The problem is that I cannot figure out how to pass a wmi object to a wmi method that accepts an array of wmi objects.
Here is the definition of the method parameters:
Name CimType Qualifiers ---- ------- ---------- Path String {ID, in} Permissions InstanceArray {EmbeddedInstance, ID, in} ResetChildren Boolean {ID, in}
Path and ResetChildren are simple parameters. They take simple values, such as "/path" and $true respectively. But I have problems with the Permissions parameter.
Here is my code
#Acquiring object that I want to pass to method $group = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Group -Filter "Name='Readers'"
Executing this code will result in an error:
Invoke-CimMethod : Unable to cast object of type 'Microsoft.Management.Infrastructure.CimInstance' to type 'M icrosoft.Management.Infrastructure.Native.InstanceHandle'. Parameter name: value At C:\somepath\script1.ps1:11 char:1 + Invoke-CimMethod -InputObject ($repositories[0]) -MethodName SetSecurity -Argume ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Invoke-CimMethod], ArgumentException + FullyQualifiedErrorId : System.ArgumentException,Microsoft.Management.Infrastructure.CimCmdlets.Invoke CimMethodCommand
If you change the code
Permissions = @($group[0]); #Trouble here
The code
Permissions = $group; #Trouble here
Then the error message will also change:
Invoke-CimMethod : Unable to cast object of type 'Microsoft.Management.Infrastructure.Native.InstanceHandle' to type 'System.Collections.IList'. Parameter name: value At C:\somepath\script1.ps1:11 char:1 + Invoke-CimMethod -InputObject ($repositories[0]) -MethodName SetSecurity -Argume ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Invoke-CimMethod], ArgumentException + FullyQualifiedErrorId : System.ArgumentException,Microsoft.Management.Infrastructure.CimCmdlets.Invoke CimMethodCommand
Any ideas on how to pass the $group method correctly?
source share