简体   繁体   中英

Basics of accessing WMI using powerShell

I'm trying to access some data available in the Windows WMI through PowerShell. I assumed this would be an easy starting point to learn the basics before possibly moving to C.

Ultimately I would like to query an (undocumented) WMI API from Open Hardware Monitor. This was suggested as part of a solution by Jens here: How to get CPU temperature?

However, I'm completely lost. How would I first load the DLL and then query it?

As a starter, I found this list from get-wmiobject -list

CIM_Sensor
CIM_BinarySensor
CIM_MultiStateSensor
CIM_DiscreteSensor
CIM_NumericSensor
CIM_TemperatureSensor
Win32_TemperatureProbe
CIM_Tachometer
CIM_VoltageSensor
Win32_VoltageProbe
CIM_CurrentSensor
Win32_CurrentProbe

Unfortunately, running get-wmiobject -class XX on any of those returns nothing. I'm expecting to be able to interrogate a sensor. Can anybody show me the basics or link me to a tutorial?

PowerShell v3 might give you more, certainly if you are looking in to Server 2012 or Windows 8 machines.

Otherwise, the issue is already in your text, they are often undocumented, or poorly documented.

I ran the Get-WMIObject -Class CIM_Sensor and Win32_TemperatureProbe and got data back, but I got nothing on a few others as well.

To find others that might be more useful you could try some of the following:

    Get-WmiObject -NameSpace 'root\wmi'
    Get-WmiObject -Class CLASSNAME | Get-Member
    (Get-WmiObject -List CLASSNAME -Amended).Qualifiers

It is important to probably look further in to WMI, as the Win32_ classes are ones Microsoft made available and are normally easier to deal with. I use a lot of WMI, but more for documentation, and checking on the OS, or making it do things, instead of pointing at the hardware, sensors, or such directly.

Some sites that might be useful as well:

http://www.dmtf.org/standards/wbem

http://collaboration.opengroup.org/pegasus/

https://en.wikipedia.org/wiki/Windows_Management_Instrumentation

Hopefully that can at least give you some more information to work from, or get you to think of something more along the lines of what you are looking for exactly.

There's an exe called wmiexplorer that will list all the WMI classes and each class' properties. It has a simple GUI and is extremely useful in finding the properties you need.

It also shows the corresponding query, which you can also experiment with. I find it very useful when I don't know which WMI class to use.

You can find more information here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM