Skip to content
Open
12 changes: 12 additions & 0 deletions adapters/wmi/Tests/wmi.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
11 changes: 7 additions & 4 deletions adapters/wmi/wmiAdapter.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -365,4 +368,4 @@ class dscResourceObject {
[string] $name
[string] $type
[PSCustomObject] $properties
}
}