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).
When executing
CimSession.QueryInstances
with a query that only selects some properties, more than the selected properties are returned.Consider the following sample:
I would expect this to only write
However it writes
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).