AvoidUsingWMICmdlet

严重性级别:警告

默认状态:始终启用

Description

该规则检测使用 Windows Management Instrumentation(WMI)指令。 自从 PowerShell 3.0 起,你应该用通用信息模型(CIM)的 cmdlet 代替 WMI cmdlet。 CIM 指令集遵循 WS-Management(WSMan)标准和 CIM 标准,后者支持管理Windows和非Windows操作系统。

不要使用这些WMI指令:

  • Get-WmiObject
  • Remove-WmiObject
  • Invoke-WmiMethod
  • Register-WmiEvent
  • Set-WmiInstance

请使用以下CIM指令小工具:

  • Get-CimInstance
  • Remove-CimInstance
  • Invoke-CimMethod
  • Register-CimIndicationEvent
  • Set-CimInstance

Example

非符合性

Get-WmiObject -Query 'Select * from Win32_Process where name LIKE "myprocess%"' | Remove-WmiObject
Invoke-WmiMethod -Class Win32_Process -Name 'Create' -ArgumentList @{ CommandLine = 'notepad.exe' }

合规的

Get-CimInstance -Query 'Select * from Win32_Process where name LIKE "myprocess%"' | Remove-CimInstance
Invoke-CimMethod -ClassName Win32_Process -MethodName 'Create' -Arguments @{ CommandLine = 'notepad.exe' }

配置规则

这个规则始终是启用的,不能配置。 请采用以下方法之一以避免使用此规则:

  • 创建一个自定义规则配置文件,只包含你想要的规则,或者排除你不想要的规则。
  • 在代码中添加相应的规则抑制属性,以抑制特定代码块的规则。 更多信息请参见使用 PSScriptAnalyzer 中的“抑制规则”部分。