Powershell中使用WMI工具例子
支持所有版本
WMI是一個(gè)強(qiáng)大的技術(shù):只需要簡(jiǎn)單的指定一個(gè)WMI類名就能返回它類的所有實(shí)例:
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
}
設(shè)置搜索條件后,代碼將搜索出包含指定屬性名的類(還可以通過通配符擴(kuò)大搜索范圍)
下面將找出所有包含“resolution”結(jié)尾的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...
接著,就可以使用類名查看它的有效數(shù)據(jù)啦:
PS> Get-WmiObject -Class CIM_CacheMemory | Select-Object -Property *
相關(guān)文章
PowerShell默認(rèn)參數(shù)$PSDefaultParameterValues結(jié)合Out-File輸出到日志文件
這篇文章主要介紹了PowerShell默認(rèn)參數(shù)$PSDefaultParameterValues結(jié)合Out-File輸出到日志文件實(shí)例,需要的朋友可以參考下2014-06-06Windows Powershell 執(zhí)行外部命令
Windows PowerShell 在使用方面與 Cmd.exe 并無多大不同,只是 Windows PowerShell 的功能更為強(qiáng)大。與 Cmd.exe 一樣,Windows PowerShell 具有內(nèi)置的腳本編寫語言,不過它比 Cmd.exe 原始的批處理語言更為靈活。Cmd.exe 做到的事情,Windows PowerShell 幾乎都能做到。2014-08-08Powershell實(shí)現(xiàn)從注冊(cè)表獲取用戶配置腳本分享
這篇文章主要介紹了Powershell實(shí)現(xiàn)從注冊(cè)表獲取用戶配置腳本分享,本文直接給出實(shí)現(xiàn)腳本源碼,需要的朋友可以參考下2015-03-03PowerShell小技巧之從函數(shù)中返回多個(gè)值
本文主要是介紹了一個(gè)可以讓一個(gè)PS腳本函數(shù)需要返回多個(gè)值的方法,它能輕松的返回你想要的多個(gè)信息,并將結(jié)果分配給多個(gè)變量,有需要的朋友參考下2014-09-09PowerShell函數(shù)參數(shù)使用智能提示功能例子
這篇文章主要介紹了PowerShell函數(shù)參數(shù)使用智能提示功能例子,這個(gè)功能一般需要在PowerShell集成開發(fā)環(huán)境ISE中才會(huì)顯示智能提示,需要的朋友可以參考下2014-07-07探索PowerShell (八) 數(shù)組、哈希表(附:復(fù)制粘貼技巧)
我們經(jīng)常在程序設(shè)計(jì)中用到的數(shù)組,同樣在腳本中很常用。本節(jié)就詳細(xì)介紹一下數(shù)組,以及哈希表在PowerShell中的使用2012-12-12PowerShell重啟服務(wù)命令Restart-Service詳細(xì)介紹
這篇文章主要介紹了PowerShell重啟服務(wù)命令Restart-Service詳細(xì)介紹,Restart-Service命令主要用來重啟一些系統(tǒng)級(jí)的服務(wù),需要的朋友可以參考下2014-08-08