diff --git a/adapters/wmi/Tests/wmi.tests.ps1 b/adapters/wmi/Tests/wmi.tests.ps1 index 67df7a982..a817bcb3c 100644 --- a/adapters/wmi/Tests/wmi.tests.ps1 +++ b/adapters/wmi/Tests/wmi.tests.ps1 @@ -108,4 +108,16 @@ Describe 'WMI adapter resource tests' { $res.afterState.VariableValue | Should -Be 'update' $res.afterState.UserName | Should -Be ("{0}\{1}" -f $env:USERDOMAIN, $env:USERNAME) } + + It 'Get works with read-only properties on Win32_ComputerSystem' -Skip:(!$IsWindows) { + $manufacturer = (Get-CimInstance -ClassName Win32_ComputerSystem).Manufacturer + $i = @{ + Manufacturer = $manufacturer + } | ConvertTo-Json + + $r = dsc resource get -r root.cimv2/Win32_ComputerSystem -i $i + $LASTEXITCODE | Should -Be 0 + $res = $r | ConvertFrom-Json + $res.actualState.Manufacturer | Should -Not -BeNullOrEmpty + } } diff --git a/adapters/wmi/wmiAdapter.psm1 b/adapters/wmi/wmiAdapter.psm1 index a45dc13f5..e0406b55c 100644 --- a/adapters/wmi/wmiAdapter.psm1 +++ b/adapters/wmi/wmiAdapter.psm1 @@ -122,11 +122,12 @@ function BuildWmiQuery { [Parameter(Mandatory = $true)] [string]$ClassName, - [Parameter(Mandatory = $true)] - [array]$Properties, - [Parameter(Mandatory = $true)] [psobject]$DesiredStateProperties, + + [Parameter()] + [AllowNull()] + [array]$Properties, [Parameter()] [switch]$KeyPropertiesOnly @@ -205,6 +206,8 @@ function GetWmiInstance { } } } + } else { + $wmi_instances = Get-CimInstance -Namespace $wmi_namespace -ClassName $wmi_classname -ErrorAction Ignore -ErrorVariable Err } } else { $wmi_instances = Get-CimInstance -Namespace $wmi_namespace -ClassName $wmi_classname -ErrorAction Ignore -ErrorVariable Err @@ -365,4 +368,4 @@ class dscResourceObject { [string] $name [string] $type [PSCustomObject] $properties -} \ No newline at end of file +}