严重级别:警告
说明
从 PowerShell 3.0 开始,CIM cmdlet 应通过 WMI cmdlet 使用。
不应使用以下 cmdlet:
Get-WmiObjectRemove-WmiObjectInvoke-WmiMethodRegister-WmiEventSet-WmiInstance
请改用以下 cmdlet:
Get-CimInstanceRemove-CimInstanceInvoke-CimMethodRegister-CimIndicationEventSet-CimInstance
CIM cmdlet 符合 WS-Management (WSMan) 标准和通用信息模型 (CIM) 标准,允许管理 Windows 和非 Windows 操作系统。
方式
更改为等效的基于 CIM 的 cmdlet。
-
Get-WmiObject->Get-CimInstance -
Remove-WmiObject->Remove-CimInstance -
Invoke-WmiMethod->Invoke-CimMethod -
Register-WmiEvent->Register-CimIndicationEvent -
Set-WmiInstance->Set-CimInstance
示例
错
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' }