Best Practice: WMI queries should not use “Select *” statements

 

What does this best practice check for?

Script-based workflows often use WMI queries to pull in the necessary data. The best practice is that WMI queries should not use placeholders (i.e. “Select *”), and should instead be well-scoped and narrow in search.

Why is it important to follow this best practice? What is the impact of not following this best practice?

WMI queries that use open-ended placeholders tend to pull in very large amounts of data, and then filter down from this. In a large instance space, this could potentially create a performance issues that could result of incomplete data and monitoring, and frequent script timeouts.

How can I fix this in my MP?

Using the Authoring Console:

1.        For the Data Source modules for all workflows that use WMI-based scripts, ensure that the scripts that these modules are using do not contain placeholders.

Using XML:

BAD

Function KMSServiceDiscovery(ByRef Name, ByRef ProcessId, ByRef State, ByRef DisplayName, ByRef PathName)

 

       Dim sNamespace

       sNamespace ="winmgmts://" & TargetComputer & "/root/cimv2"

       

       Dim oKMSServices, oService

       Set oKMSServices = WMIExecQuery(sNamespace, "SELECT * FROM Win32_Service WHERE Name ='sppsvc' OR Name = 'slsvc'")

       

       if oKMSServices.Count = 1 Then

           For Each oService in oKMSServices

                Name = oService.Name

               ProcessId = oService.ProcessId

               State = oService.State

               DisplayName = oService.DisplayName

               PathName = oService.PathName

           Next

           KMSServiceDiscovery = True

       Else

           KMSServiceDiscovery = False          

       End If

       

End Function

 

GOOD

Function KMSServiceDiscovery(ByRef Name, ByRef ProcessId, ByRef State, ByRef DisplayName, ByRef PathName)

 

       Dim sNamespace

       sNamespace ="winmgmts://" & TargetComputer & "/root/cimv2"

       

       Dim oKMSServices, oService

       Set oKMSServices = WMIExecQuery(sNamespace, "SELECT Name, ProcessId, State, DisplayName, PathName FROM Win32_Service WHERE Name = 'sppsvc' OR Name = 'slsvc'")

       

       if oKMSServices.Count = 1 Then

           For Each oService in oKMSServices

                Name = oService.Name

               ProcessId = oService.ProcessId

               State = oService.State

               DisplayName = oService.DisplayName

               PathName = oService.PathName

           Next

           KMSServiceDiscovery = True

       Else

           KMSServiceDiscovery = False          

       End If

       

End Function