Powershell中使用WMI工具例子
支持所有版本
wmi是一个强大的技术:只需要简单的指定一个wmi类名就能返回它类的所有实例:
ps> get-wmiobject -class win32_bios
smbiosbiosversion : 76cn27ww
manufacturer : lenovo
name : 76cn27ww
serialnumber : 1006250300406
version : lenovo - 1
你如何知道它有哪些类呢?这里有一款查找工具:
function find-wmiclass
{
param
(
[parameter(mandatory=$true)]
$searchterm = 'resolution'
)
get-wmiobject -class * -list |
where-object { $_.properties.count -ge 3 } |
where-object { $_.name -notlike 'win32_perf*' } |
where-object {
$listofnames = $_.properties | select-object -expandproperty name
($listofnames -like "*$searchterm*") -ne $null
} |
sort-object -property name
}
设置搜索条件后,代码将搜索出包含指定属性名的类(还可以通过通配符扩大搜索范围)
下面将找出所有包含“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_cachememory | select-object -property *