Skip to content

Commit bbca66a

Browse files
committed
solve issue in binary output
1 parent 39ff59c commit bbca66a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

powershell-adapter/psDscAdapter/psDscAdapter.psm1

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,12 @@ function Invoke-DscCacheRefresh {
8888
)
8989
$DscResourceInfo = [DscResourceInfo]::new()
9090
$dscResource.PSObject.Properties | ForEach-Object -Process {
91-
if ($null -eq $_.Value) { $_.Value = '' }
92-
$DscResourceInfo.$($_.Name) = $_.Value
91+
if ($null -ne $_.Value) {
92+
$DscResourceInfo.$($_.Name) = $_.Value
93+
}
94+
else {
95+
$DscResourceInfo.$($_.Name) = ''
96+
}
9397
}
9498
if ($dscResource.ModuleName) {
9599
$moduleName = $dscResource.ModuleName
@@ -286,13 +290,13 @@ function Get-ActualState {
286290

287291
# using the cmdlet from PSDesiredStateConfiguration module in Windows
288292
try {
289-
$getResult = $PSDesiredStateConfiguration.invoke({ param($Name, $Property) Invoke-DscResource -Name $Name -Method Get -ModuleName @{ModuleName = 'PSDesiredStateConfiguration'; ModuleVersion = '1.1' } -Property $Property }, $cachedDscResourceInfo.Name, $property )
293+
$getResult = $PSDesiredStateConfiguration.invoke({ param($Name, $Property) Invoke-DscResource -Name $Name -Method Get -ModuleName @{ModuleName = 'PSDesiredStateConfiguration'; ModuleVersion = '1.1' } -Property $Property -ErrorAction Stop }, $cachedDscResourceInfo.Name, $property )
290294

291295
$trace = @{'Debug' = 'TEMP output: ' + $($getResult | ConvertTo-Json -Depth 10 -Compress) } | ConvertTo-Json -Compress
292296
$host.ui.WriteErrorLine($trace)
293297

294298
# only return DSC properties from the Cim instance
295-
$cachedDscResourceInfo.Properties.Name | ForEach-Object -Begin { $getDscResult = @{} } -Process { $getDscResult[$_] = $getResult.$_ }
299+
$getresult.psobject.Properties.name | Where-Object { 'CimClass','CimInstanceProperties','CimSystemProperties' -notcontains $_ } | ForEach-Object -Begin { $getDscResult = @{} } -Process { $getDscResult[$_] = $getResult.$_ }
296300

297301
# set the properties of the OUTPUT object from the result of Get-TargetResource
298302
$addToActualState.properties = $getDscResult

0 commit comments

Comments
 (0)