Skip to content

Commit 350816b

Browse files
committed
Merge pull request #105 from PowerShell/AvoidWMICmdletRuleDocumentationBranch
Avoid wmi cmdlet rule documentation
2 parents 974a255 + 5e7d2f6 commit 350816b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#AvoidUsingWMICmdlet
2+
**Severity Level: Warning**
3+
4+
5+
##Description
6+
7+
Avoid Using Get-WMIObject, Remove-WMIObject, Invoke-WmiMethod, Register-WmiEvent, Set-WmiInstance
8+
9+
For PowerShell 3.0 and above, use CIM cmdlet which perform the same tasks as the WMI cmdlets. The CIM cmdlets comply with WS-Management (WSMan) standards and with the Common Information Model (CIM) standard, which enables the cmdlets to use the same techniques to manage Windows computers and those running other operating systems.
10+
11+
##How to Fix
12+
13+
Use corresponding CIM cmdlets such as Get-CIMInstance, Remove-CIMInstance, Invoke-CIMMethod, Register-CimIndicationEvent, Set-CimInstance
14+
15+
##Example
16+
17+
Wrong:
18+
```
19+
Get-WmiObject -Query 'Select * from Win32_Process where name LIKE "myprocess%"' | Remove-WmiObject
20+
Invoke-WmiMethod –Class Win32_Process –Name "Create" –ArgumentList @{ CommandLine = "notepad.exe" }
21+
```
22+
Correct:
23+
```
24+
Get-CimInstance -Query 'Select * from Win32_Process where name LIKE "myprocess%"' | Remove-CIMInstance
25+
Invoke-CimMethod –ClassName Win32_Process –MethodName "Create" –Arguments @{ CommandLine = "notepad.exe" }
26+
```

0 commit comments

Comments
 (0)