华域联盟 PowerShell Powershell中使用WMI工具例子

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中使用WMI工具例子

转载请保留出处和原文链接:https://www.cnhackhy.com/14796.htm

本文来自网络,不代表华域联盟立场,转载请注明出处。

作者: sterben

发表回复

联系我们

联系我们

2551209778

在线咨询: QQ交谈

邮箱: [email protected]

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部