@@ -186,22 +186,26 @@ function GetWmiInstance {
186186 $class = Get-CimClass - Namespace $wmi_namespace - ClassName $wmi_classname - ErrorAction Stop
187187
188188 if ($DesiredState.properties ) {
189- $properties = GetValidCimProperties - CimClass $class - ClassName $wmi_classname - Properties $DesiredState.properties - SkipReadOnly
189+ # For GET operations, we should NOT skip read-only properties since we're just reading them
190+ $properties = GetValidCimProperties - CimClass $class - ClassName $wmi_classname - Properties $DesiredState.properties
190191
191- $query = BuildWmiQuery - ClassName $wmi_classname - Properties $properties - DesiredStateProperties $DesiredState.properties
192+ # Only build query if we have properties to query
193+ if ($properties -and $properties.Count -gt 0 ) {
194+ $query = BuildWmiQuery - ClassName $wmi_classname - Properties $properties - DesiredStateProperties $DesiredState.properties
192195
193- if ($query ) {
194- " Query: $query " | Write-DscTrace - Operation Debug
195- $wmi_instances = Get-CimInstance - Namespace $wmi_namespace - Query $query - ErrorAction Ignore - ErrorVariable err
196+ if ($query ) {
197+ " Query: $query " | Write-DscTrace - Operation Debug
198+ $wmi_instances = Get-CimInstance - Namespace $wmi_namespace - Query $query - ErrorAction Ignore - ErrorVariable err
196199
197- if ($null -eq $wmi_instances ) {
198- " No WMI instances found using query '$query '. Retrying with key properties only." | Write-DscTrace - Operation Debug
199- $keyQuery = BuildWmiQuery - ClassName $wmi_classname - Properties $properties - DesiredStateProperties $DesiredState.properties - KeyPropertiesOnly
200+ if ($null -eq $wmi_instances ) {
201+ " No WMI instances found using query '$query '. Retrying with key properties only." | Write-DscTrace - Operation Debug
202+ $keyQuery = BuildWmiQuery - ClassName $wmi_classname - Properties $properties - DesiredStateProperties $DesiredState.properties - KeyPropertiesOnly
200203
201- if ($keyQuery ) {
202- $wmi_instances = Get-CimInstance - Namespace $wmi_namespace - Query $keyQuery - ErrorAction Ignore - ErrorVariable err
203- if ($null -eq $wmi_instances ) {
204- " No WMI instances found using key properties query '$keyQuery '." | Write-DscTrace - Operation Debug
204+ if ($keyQuery ) {
205+ $wmi_instances = Get-CimInstance - Namespace $wmi_namespace - Query $keyQuery - ErrorAction Ignore - ErrorVariable err
206+ if ($null -eq $wmi_instances ) {
207+ " No WMI instances found using key properties query '$keyQuery '." | Write-DscTrace - Operation Debug
208+ }
205209 }
206210 }
207211 }
0 commit comments