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 *
相关文章
PowerShell启用winrm失败:拒绝访问 0x80070005 -2147024891
这篇文章主要介绍了PowerShell启用winrm失败:拒绝访问 0x80070005 -2147024891,本文给出了详细的排查步骤和解决方法,需要的朋友可以参考下2015-06-06PowerShell使用Clear-Content命令删除、清空文件内容的例子
这篇文章主要介绍了PowerShell使用Clear-Content命令删除、清空文件内容的例子,并对Clear-Content作了介绍,需要的朋友可以参考下2014-08-08PowerShell中使用Get-Date获取日期时间并格式化输出的例子
这篇文章主要介绍了PowerShell中使用Get-Date获取日期时间并格式化输出的例子,本文讲解了直接调用Get-Date、在Write-Host中使用Get-Date、格式化输出的方法,需要的朋友可以参考下2014-08-08如何利用PowerShell监控Win-Server性能详解
这篇文章主要给大家介绍了关于如何利用PowerShell监控Win-Server性能的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2018-10-10PowerShell中使用正则和ValidateSet验证参数合法性
这篇文章主要介绍了PowerShell中使用正则和ValidateSet验证参数合法性,本文分别给出了验证实例,讲解如何验证参数的正确性,需要的朋友可以参考下2015-04-04
最新评论