Skip to content
This repository was archived by the owner on Jun 14, 2024. It is now read-only.
This repository was archived by the owner on Jun 14, 2024. It is now read-only.

SELECT returns more properties than requested #50

@ericstj

Description

@ericstj

When executing CimSession.QueryInstances with a query that only selects some properties, more than the selected properties are returned.

Consider the following sample:

using Microsoft.Management.Infrastructure;
using System;

namespace selectSample
{
    class Program
    {
        static void Main(string[] args)
        {
            RunQuery("SELECT Model from Win32_ComputerSystem");
        }

        static void RunQuery(string query)
        {
            Console.WriteLine(query);
            using (var session = CimSession.Create(null))
                foreach (CimInstance instance in session.QueryInstances(@"root\cimv2", "WQL", query))
                    using (instance)
                        foreach (CimProperty property in instance.CimInstanceProperties)
                            if (property.Value != null)
                                Console.WriteLine($"  {property.Name}: {property.Value}");
        }
    }
}

I would expect this to only write

SELECT Model from Win32_ComputerSystem
  Model: My fancy desktop machine

However it writes

SELECT Model from Win32_ComputerSystem
  Name: machine-name
  Model: My fancy desktop machine

Not to mention that when selecting, it still returns all properties with values null. This can be ignored, but I cannot determine how to ignore things that weren't selected (unless I parse the query myself).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions