Skip to content

Commit 72858d2

Browse files
committed
Update AvoidUsingWMICmdlet.md
1 parent f3b55e6 commit 72858d2

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
#AvoidAlias
1+
#AvoidUsingWMICmdlet
22
**Severity Level: Warning**
33

44

55
##Description
66

7-
An alias is an alternate name or nickname for a cmdlet or for a command element, such as a function, script, file, or executable file. But when writing scripts that will potentially need to be maintained over time, either by the original author or another Windows PowerShell scripter, please consider using full cmdlet name instead of alias. Aliases can introduce these problems, readability, understandability and availability.
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.
810

911
##How to Fix
1012

11-
Please consider using full cmdlet name instead of alias.
13+
Use corresponding CIM cmdlets such as Get-CIMInstance, Remove-CIMInstance, Invoke-CIMMethod, Register-CimIndicationEvent, Set-CimInstance
1214

1315
##Example
1416

15-
Wrong: gps | Where-Object {$_.WorkingSet -gt 20000000}
16-
17-
Correct: Get-Process | Where-Object {$_.WorkingSet -gt 20000000}
17+
Get-CimInstance -Query 'Select * from Win32_Process where name LIKE "myprocess%"' | Remove-CIMInstance
18+
Invoke-CimMethod –ClassName Win32_Process –MethodName "Create" –Arguments @{ CommandLine = "notepad.exe" }

0 commit comments

Comments
 (0)