国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PowerShell > 正文

Powershell小技巧之使用WMI工具

2020-10-29 21:00:47
字體:
供稿:網(wǎng)友

WMI是一個強(qiáng)大的技術(shù):只需要簡單的指定一個WMI類名就能返回它類的所有實(shí)例:

復(fù)制代碼 代碼如下:

PS> Get-WmiObject -Class Win32_BIOS

SMBIOSBIOSVersion : 76CN27WW
Manufacturer      : LENOVO
Name              : 76CN27WW
SerialNumber      : 1006250300406
Version           : LENOVO - 1

你如何知道它有哪些類呢?這里有一款查找工具:

復(fù)制代碼 代碼如下:

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類:

復(fù)制代碼 代碼如下:

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ù)啦:

復(fù)制代碼 代碼如下:

PS> Get-WmiObject -Class CIM_CacheMemory | Select-Object -Property *

心得:

其實(shí)有個類似功能的圖形工具比這段代碼更方便更直觀,它叫ScriptomaticV2。

支持Powershell所有版本

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 防城港市| 桐庐县| 渭南市| 绥芬河市| 杭州市| 襄汾县| 屏东县| 凉城县| 宣威市| 重庆市| 汝南县| 丰城市| 内乡县| 仙居县| 黔西| 伊川县| 缙云县| 余干县| 西盟| 伊川县| 巧家县| 二连浩特市| 罗江县| 昌吉市| 大同县| 合川市| 汝南县| 广昌县| 绩溪县| 依安县| 黑河市| 航空| 蒲城县| 尉氏县| 辽中县| 台东县| 凤翔县| 色达县| 凭祥市| 望城县| 大田县|