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

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.。不过,我试了一下,可以得到输出,不过不知道是不是文章中提到的…)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值