Thursday, January 30, 2014

PowerShell - WMI and filters

Just a quick note to compare two methods of retrieving WMI information. Take the following examples"

Write-Host "Method One"
Get-WmiObject Win32_service -ComputerName MyPC|Where{$_.StartMode -eq "Disabled"}
Write-Host "Method Two"
Get-WmiObject Win32_service -ComputerName MyPC -Filter "StartMode = 'Disabled'"

Both methods produce the exact name results. However, the second method using -FILTER is much faster. The first method gets the details of every service on the remote machine and then cherry picks the information locally based on the WHERE clause. The second method only pulls the information you require and that is where the performance increase occurs.


No comments:

Post a Comment