PowerShell Queries and Square Brackets

Chiyo OdikaGENERAL, PowerShell, SCOM, UncategorizedLeave a Comment

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:

 image

Ok so this returns expected values.

Now let’s return a specific object instead of all objects:

image

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.

image

Now when we type out the same command with double escapes, we get the expected output. Cheers!

The following two tabs change content below.
Chiyo's expertise spans multiple platforms. He holds Microsoft Private Cloud, and Server Infrastructure certifications, and avidly enjoys working on deployments of Microsoft's Server and Cloud Platforms, including Microsoft Systems Center, Windows Server, and Microsoft Azure.

Latest posts by Chiyo Odika (see all)

Chiyo OdikaPowerShell Queries and Square Brackets