I recently encountered an interesting issue while trying to query class instances in SCOM. The class instances for certain classes will return the parent class as well as associated classes in the following format: [Parent Class Name].attribute. For instance the class instance for Microsoft.Windows.Computer returns the following:
$SCOMClass = Get-SCOMClass -Name Microsoft.Windows.Computer
(Get-SCOMClassInstance -Class $SCOMClass) | Select-Object *
Ok so this returns expected values.
Now let's return a specific object instead of all objects:
(Get-SCOMClassInstance -Class $SCOMClass) | Select-Object [Microsoft.Windows.Computer].LogicalProcessors
This returns nothing, even though we clearly see values for the Logical Processors when we select all objects.
After some checking, re-checking, and second guessing, I found an article
that's as short as the solution is simple. Apparently double-escaping is required for the parser to properly handle square brackets in strings.
Note that the double-escapes are not single quotes. :) This one got me initially.
(Get-SCOMClassInstance -Class $SCOMClass) | Select-Object ``[Microsoft.Windows.Computer`].LogicalProcessors
Now when we type out the same command with double escapes, we get the expected output. Cheers!