《Learn Windows PowerShell in a Month of Lunches Third Edition》读书笔记—CHAPTER 14 Using WMI and CIM

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_41104353/article/details/82284857

14.1 WMI essentials

At the top level, WMI is organized into namespaces.
Think of a namespace as a sort of folder that ties to a specific product or technology.

Within a namespace, WMI is divided into a series of classes.
A class represents a management component that WMI knows how to query.

参考 http://www.trainingtech.net/configure-wmi-control-in-windows-8/ 查看 WMI的名字空间。

比如,我们可以通过一下命令从 root\securitycenter2 查询 AntiSpywareProduct
PS C:\> Get-CimInstance -Namespace root\securitycenter2 -ClassName antispywareproduct

14.3 Exploring WMI

我们有三种方式来寻找我们想要的class

  1. 使用WMI Explore:可以到 https://github.com/vinaypamnani/wmie2/releases 下载一个 WMI Explorer。(打开后点一下左上角的 connect ,双击节点可以查看 class。双击class,在右下角点Execute 就可以查看详细信息了)
  2. 使用搜索引擎
  3. 使用PowerShell本身。比如我们想要查找关于磁盘(disk)的命令,我们可以首先猜测正确的名字空间,我们知道 root\CIMv2 包含所有硬件的内容,所以我们运行这条命令:Get-WmiObject -Namespace root\CIMv2 -list | where name -like '*dis*' ,最后我们找到 Win32_LogicalDisk

14.4 Choose your weapon: WMI or CIM

对于v3及以后的PowerShell,我们有两种方式与WMI交互:
1. 所谓的 WMI cmdlets,如 Get-WmiObjectInvoke-WmiMethod 。但是微软不再继续开发它们了。
2. 新的 CIM cmdlets ,如 Get-CimInstanceInvoke-CimMethod 。这是微软前进方向。使用 Get-Command -noun CIM* 或者 gcm -module cimcmdlets 命令可以看到微软提供了一些此类方法。

14.8 Common points of confusion

The operating system itself doesn’t contain any WMI documentation, so PowerShell’s help function wouldn’t have any place to go look for it.
因此我们运行 help win32_service 不会得到结果。(原文是you might be inclined to run something like help win32_service right inside PowerShell. Sadly, that won’t work.。不过,我试了一下,可以得到输出,不过不知道是不是文章中提到的…)

猜你喜欢

转载自blog.csdn.net/sinat_41104353/article/details/82284857