Skip to content

Commit 95c1f1e

Browse files
author
Steve Lee (POWERSHELL HE/HIM) (from Dev Box)
committed
fix wmi adapter and tests
1 parent 2bb1bcf commit 95c1f1e

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

wmi-adapter/Tests/wmi.tests.ps1

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ Describe 'WMI adapter resource tests' {
4040
$r = Get-Content -Raw $configPath | dsc config get -f -
4141
$LASTEXITCODE | Should -Be 0
4242
$res = $r | ConvertFrom-Json
43-
$res.results[0].result.actualState[0].LastBootUpTime | Should -BeNullOrEmpty
44-
$res.results[0].result.actualState[0].Caption | Should -Not -BeNullOrEmpty
45-
$res.results[0].result.actualState[0].Version | Should -Not -BeNullOrEmpty
46-
$res.results[0].result.actualState[0].OSArchitecture | Should -Not -BeNullOrEmpty
43+
$res.results[0].result.actualState.result[0].properties.LastBootUpTime | Should -BeNullOrEmpty
44+
$res.results[0].result.actualState.result[0].properties.Caption | Should -Not -BeNullOrEmpty
45+
$res.results[0].result.actualState.result[0].properties.Version | Should -Not -BeNullOrEmpty
46+
$res.results[0].result.actualState.result[0].properties.OSArchitecture | Should -Not -BeNullOrEmpty
4747
}
4848

4949
It 'Example config works' -Skip:(!$IsWindows) {
@@ -52,10 +52,10 @@ Describe 'WMI adapter resource tests' {
5252
$LASTEXITCODE | Should -Be 0
5353
$r | Should -Not -BeNullOrEmpty
5454
$res = $r | ConvertFrom-Json
55-
$res.results[1].result.actualState[0].Name | Should -Not -BeNullOrEmpty
56-
$res.results[1].result.actualState[0].BootupState | Should -BeNullOrEmpty
57-
$res.results[1].result.actualState[1].Caption | Should -Not -BeNullOrEmpty
58-
$res.results[1].result.actualState[1].BuildNumber | Should -BeNullOrEmpty
59-
$res.results[1].result.actualState[4].AdapterType | Should -BeLike "Ethernet*"
55+
$res.results[1].result.actualState.result[0].properties.Name | Should -Not -BeNullOrEmpty
56+
$res.results[1].result.actualState.result[0].properties.BootupState | Should -BeNullOrEmpty
57+
$res.results[1].result.actualState.result[1].properties.Caption | Should -Not -BeNullOrEmpty
58+
$res.results[1].result.actualState.result[1].properties.BuildNumber | Should -BeNullOrEmpty
59+
$res.results[1].result.actualState.result[4].properties.AdapterType | Should -BeLike "Ethernet*"
6060
}
6161
}

wmi-adapter/wmi.resource.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ elseif ($Operation -eq 'Get')
8181

8282
$result = @()
8383

84-
foreach($r in $inputobj_pscustomobj.resources)
84+
foreach ($r in $inputobj_pscustomobj.resources)
8585
{
8686
$type_fields = $r.type -split "/"
8787
$wmi_namespace = $type_fields[0].Replace('.','\')
@@ -133,7 +133,7 @@ elseif ($Operation -eq 'Get')
133133

134134
if ($wmi_instances)
135135
{
136-
$instance_result = @{}
136+
$instance_result = [ordered]@{}
137137
# TODO: for a `Get`, they key property must be provided so a specific instance is returned rather than just the first
138138
$wmi_instance = $wmi_instances[0] # for 'Get' we return just first matching instance; for 'export' we return all instances
139139
$wmi_instance.psobject.properties | %{
@@ -153,11 +153,11 @@ elseif ($Operation -eq 'Get')
153153
}
154154
}
155155

156-
$result += @($instance_result)
156+
$result += [pscustomobject]@{ name = $r.name; type = $r.type; properties = $instance_result }
157157
}
158158
}
159159

160-
$result | ConvertTo-Json -Compress
160+
@{result = $result } | ConvertTo-Json -Depth 10 -Compress
161161
}
162162
elseif ($Operation -eq 'Validate')
163163
{

0 commit comments

Comments
 (0)