Skip to content

no-wmi-cmdlets

PowerShellsuspiciousno fixdefault: warnpowershell/psscriptanalyzer

Reports a call of Get-WmiObject, Invoke-WmiMethod, Register-WmiEvent, Remove-WmiObject or Set-WmiInstance.

The WMI cmdlets are not in PowerShell 7 and later. The CIM cmdlets (Get-CimInstance, Invoke-CimMethod) do the same work on Windows, use the newer remoting protocol, and are in both editions.

To fix, use the CIM cmdlet of the same job.

Reported
...
ConvertTo-SecureString $p
...
$p -AsPlainText
Get-WmiObject Win32_Process
Get-CimInstance Win32_Process
...
powershell:
lint:
rules:
no-wmi-cmdlets: warn # off, warn (default), error

Enabled by the presets: powershell/psscriptanalyzer.

Suppress one line with sudsy-disable-next-line no-wmi-cmdlets in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
psscriptanalyzer PSAvoidUsingWMICmdlet full