Skip to content

Commit b716bb1

Browse files
authored
Merge pull request #1254 from Gijsreyn/gh-1253/fix/allow-readonly-wmi
Fix read-only properties on `get` operation WMI adapter
2 parents a8a57b6 + d33fd59 commit b716bb1

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

adapters/wmi/Tests/wmi.tests.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,16 @@ Describe 'WMI adapter resource tests' {
108108
$res.afterState.VariableValue | Should -Be 'update'
109109
$res.afterState.UserName | Should -Be ("{0}\{1}" -f $env:USERDOMAIN, $env:USERNAME)
110110
}
111+
112+
It 'Get works with read-only properties on Win32_ComputerSystem' -Skip:(!$IsWindows) {
113+
$manufacturer = (Get-CimInstance -ClassName Win32_ComputerSystem).Manufacturer
114+
$i = @{
115+
Manufacturer = $manufacturer
116+
} | ConvertTo-Json
117+
118+
$r = dsc resource get -r root.cimv2/Win32_ComputerSystem -i $i
119+
$LASTEXITCODE | Should -Be 0
120+
$res = $r | ConvertFrom-Json
121+
$res.actualState.Manufacturer | Should -Be $manufacturer
122+
}
111123
}

adapters/wmi/wmiAdapter.psm1

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,12 @@ function BuildWmiQuery {
122122
[Parameter(Mandatory = $true)]
123123
[string]$ClassName,
124124

125-
[Parameter(Mandatory = $true)]
126-
[array]$Properties,
127-
128125
[Parameter(Mandatory = $true)]
129126
[psobject]$DesiredStateProperties,
127+
128+
[Parameter()]
129+
[AllowNull()]
130+
[array]$Properties,
130131

131132
[Parameter()]
132133
[switch]$KeyPropertiesOnly
@@ -205,6 +206,8 @@ function GetWmiInstance {
205206
}
206207
}
207208
}
209+
} else {
210+
$wmi_instances = Get-CimInstance -Namespace $wmi_namespace -ClassName $wmi_classname -ErrorAction Ignore -ErrorVariable Err
208211
}
209212
} else {
210213
$wmi_instances = Get-CimInstance -Namespace $wmi_namespace -ClassName $wmi_classname -ErrorAction Ignore -ErrorVariable Err
@@ -365,4 +368,4 @@ class dscResourceObject {
365368
[string] $name
366369
[string] $type
367370
[PSCustomObject] $properties
368-
}
371+
}

0 commit comments

Comments
 (0)