原始链接:PowerShell 技能连载 - WMI 搜索工具
发表日期:2014-10-15
适用于 PowerShell 所有版本
WMI 是一个很棒很强大的技术:只需要指定一个 WMI 类名,您就可以获取该类的所有实体。- PS> Get-WmiObject -Class Win32_BIOS
-
-
- SMBIOSBIOSVersion : 76CN27WW
- Manufacturer : LENOVO
- Name : 76CN27WW
- SerialNumber : 1006250300406
- Version : LENOVO - 1
复制代码 那么如何知道有哪些 WMI 类呢?以下是一个搜索工具函数:- function Find-WMIClass
- {
- param
- (
- [Parameter(Mandatory=$true)]
- $SearchTerm = 'Resolution'
- )
-
- Get-WmiObject -Class [i] -List [/i]
- Where-Object { $[i].Properties.Count -ge 3 } [/i]
- Where-Object { $[i].Name -notlike 'Win32[/i]Perf[i]' } [/i]
- Where-Object {
- $ListOfNames = $_.Properties | Select-Object -ExpandProperty Name
- ($ListOfNames -like "*$SearchTerm*") -ne $null
- } |
- Sort-Object -Property Name
- }
复制代码 只需要指定一个搜索条件。该函数将会查找所有属性名中包含搜索条件的 WMI 类(可以用通配符来扩大搜索范围)。
这段代码能搜索属性以“resolution”结尾的 WMI 类:- PS> Find-WMIClass -SearchTerm *resolution
-
-
- NameSpace: ROOT\cimv2
-
- Name Methods Properties
- ---- ------- ----------
- CIM_CacheMemory {SetPowerState, R... {Access, AdditionalErr...
- CIM_CurrentSensor {SetPowerState, R... {Accuracy, Availabilit...
- CIM_FlatPanel {SetPowerState, R... {Availability, Caption...
- CIM_Memory {SetPowerState, R... {Access, AdditionalErr...
- CIM_MonitorResolution {} {Caption, Description,...
- CIM_NonVolatileStorage {SetPowerState, R... {Access, AdditionalErr...
- CIM_NumericSensor {SetPowerState, R... {Accuracy, Availabilit...
- CIM_PCVideoController {SetPowerState, R... {AcceleratorCapabiliti...
- CIM_PointingDevice {SetPowerState, R... {Availability, Caption...
- CIM_Printer {SetPowerState, R... {Availability, Availab...
- CIM_Tachometer {SetPowerState, R... {Accuracy, Availabilit...
- CIM_TemperatureSensor {SetPowerState, R... {Accuracy, Availabilit...
- CIM_VideoController {SetPowerState, R... {AcceleratorCapabiliti...
- CIM_VideoControllerResolution {} {Caption, Description,...
- CIM_VolatileStorage {SetPowerState, R... {Access, AdditionalErr...
- CIM_VoltageSensor {SetPowerState, R... {Accuracy, Availabilit...
- Win32_CacheMemory {SetPowerState, R... {Access, AdditionalErr...
- Win32_CurrentProbe {SetPowerState, R... {Accuracy, Availabilit...
- Win32_DisplayControllerConfigura... {} {BitsPerPixel, Caption...
- Win32_MemoryArray {SetPowerState, R... {Access, AdditionalErr...
- Win32_MemoryDevice {SetPowerState, R... {Access, AdditionalErr...
- Win32_NetworkAdapterConfiguration {EnableDHCP, Rene... {ArpAlwaysSourceRoute,...
- Win32_PointingDevice {SetPowerState, R... {Availability, Caption...
- Win32_Printer {SetPowerState, R... {Attributes, Availabil...
- Win32_PrinterConfiguration {} {BitsPerPel, Caption, ...
- Win32_SMBIOSMemory {SetPowerState, R... {Access, AdditionalErr...
- Win32_TemperatureProbe {SetPowerState, R... {Accuracy, Availabilit...
- Win32_VideoConfiguration {} {ActualColorResolution...
- Win32_VideoController {SetPowerState, R... {AcceleratorCapabiliti...
- Win32_VoltageProbe {SetPowerState, R... {Accuracy, Availabilit...
复制代码 下一步,选择一个类名并观察它的实际数据:- PS> Get-WmiObject -Class CIM[i]CacheMemory [/i] Select-Object -Property *
复制代码 本文国际来源:WMI Search Tool |