|
25 | 25 |
|
26 | 26 | /** |
27 | 27 | * WMI Stub implementation based in PowerShell (jPowerShell) |
28 | | - * |
| 28 | + * |
29 | 29 | * @author Javier Garcia Alonso |
30 | 30 | */ |
31 | 31 | class WMIPowerShell implements WMIStub { |
| 32 | + |
32 | 33 | private static final String NAMESPACE_PARAM = "-Namespace "; |
33 | | - private static final String GETWMIOBJECT_COMMAND = "Get-WMIObject "; |
| 34 | + private static final String GETWMIOBJECT_COMMAND = "Get-WMIObject "; |
34 | 35 |
|
35 | 36 | private static String executeCommand(String command) throws WMIException { |
36 | 37 | String commandResponse = null; |
@@ -110,16 +111,19 @@ public String queryObject(String wmiClass, List<String> wmiProperties, List<Stri |
110 | 111 | if (!"*".equals(namespace)) { |
111 | 112 | command += NAMESPACE_PARAM + namespace; |
112 | 113 | } |
113 | | - if(wmiProperties == null ||wmiProperties.isEmpty()){ |
114 | | - wmiProperties = Collections.singletonList("*"); |
| 114 | + List<String> usedWMIProperties; |
| 115 | + if (wmiProperties == null || wmiProperties.isEmpty()) { |
| 116 | + usedWMIProperties = Collections.singletonList("*"); |
| 117 | + } else { |
| 118 | + usedWMIProperties = wmiProperties; |
115 | 119 | } |
116 | 120 |
|
117 | 121 | command += " | "; |
118 | 122 |
|
119 | | - command += "Select-Object " + Joiner.on(", ").join(wmiProperties)+" -excludeproperty \"_*\" | "; |
| 123 | + command += "Select-Object " + Joiner.on(", ").join(usedWMIProperties) + " -excludeproperty \"_*\" | "; |
120 | 124 |
|
121 | | - if(conditions!=null && !conditions.isEmpty()){ |
122 | | - for(String condition : conditions) { |
| 125 | + if (conditions != null && !conditions.isEmpty()) { |
| 126 | + for (String condition : conditions) { |
123 | 127 | command += "Where-Object -FilterScript {" + condition + "} | "; |
124 | 128 | } |
125 | 129 | } |
|
0 commit comments