Why does -Exclude "_*" work in 1 circumstance but not another?

Hi,

This is more for my own learning then anything. I’m finding that Get-WMIObject with a -query is faster then passing the whole Get-WMIObject through the pipe and using | Select-Object on it.

But I’m having a bit of trouble then working with the results.

My issue is, - this is just some example code. I’m actually querying for specific fields but it still brings back all the “__Name” fields. So trying to do the Select after to pass less across the pipe.

This works

Get-WmiObject win32_processor | select * -exclude "_*"

This doesn’t?

$test = Get-WMIObject -query "SELECT DeviceID, Name, Description, NumberofCores, NumberOfLogicalProcessors, MaxClockSpeed, SocketDesignation, Status FROM Win32_Processor"
$Test | Select -exclude "_*"

I thought I had sussed the pipe and variables. But this now calls into question that.

My end goal is to query WMI, and output the result to a text-file or some other variable to work with, without all the extra gumf.

My assumption is that you are trying to exclude the double underscore properties, which are default properties for WMI. Check out this blog that explains what they are and how to get only what you want.

The -Query is faster because you are only returning those specific properties. You can replicate this by using -Properties:

Get-WMIObject -Class Win32_Processor -Properties DeviceID, Name, Description, NumberofCores, NumberOfLogicalProcessors, MaxClockSpeed, SocketDesignation, Status