UndvikUsingWMICmdlet

allvarlighetsgrad: Varning

Beskrivning

Denna regel upptäcker användningen av Windows Management Instrumentation (WMI)-cmdlets. Sedan PowerShell 3.0 bör du använda Common Information Model (CIM)-cmdlets istället för WMI-cmdlets. CIM-cmdlets uppfyller WS-Management (WSMan)-standarder och CIM-standarden, som möjliggör hantering av Windows och icke-Windows operativsystem.

Använd inte dessa WMI-cmdlets:

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

Använd istället dessa CIM-cmdlets:

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

Example

Ej överensstämmande

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

Godkänd

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