I’m using the new CIM cmdlets released in PS3, but there are a few things I don’t seem to be able to do with CIM that I was able to do with the deprecated WMI cmdlets.
Here is an example:
([wmiclass] 'Win32_Process').Properties['WriteTransferCount'].Qualifiers.Remove['read']
This will retrieve the WMI class Win32_Process, get the property WriteTransferCount and remove the qualifier ‘read’ from it using the Remove() method.
Using CIM?
(Get-CimClass Win32_Process).CimClassProperties['WriteTransferCount'].Qualifiers
So far so good, this works so far. Now let’s invoke the Remove() method as above:
(Get-CimClass Win32_Process).CimClassProperties['WriteTransferCount'].Qualifiers.Remove['Read']
#
Method invocation failed because [Microsoft.Management.Infrastructure.Internal.Data.CimQualifierOfProperty] does not contain a method named 'Remove'.
At line:1 char:1
+ [Get-CimClass Win32_Process].CimClassProperties['WriteTransferCount'] ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: [:] [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
#
Right, of course it doesn’t, because CIM classes don’t expose methods. You need to use Invoke-CimMethod
But… reading through the help of Invoke-CimMethod, one notices that it accepts either a CimClass object, or a CimInstance object.
Unfortunately, our object is of type CimQualifierOfProperty, so Invoke-CimMethod refuses to accept it.
I can’t find any way of making this work. I looked up the classes in MSDN, spent over 1h searching the internet, no one seems to be using this class yet (other than PowerShell) and there doesn’t appear to be a way to do this using the new Cim objects (notice I said objects and not cmdlets, I’m fine going into .NET territory, but still can’t find a way of doing it).
Is it me or can’t this be done at all?