Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions powershell-adapter/Tests/win_powershellgroup.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ Describe 'WindowsPowerShell adapter resource tests' {
$res.actualState.result.properties.DestinationPath | Should -Be "$testFile"
}

It 'Set works on Binary "File" resource' -Skip:(!$IsWindows){

$testFile = "$testdrive\test.txt"
$r = '{"DestinationPath":"' + $testFile.replace('\','\\') + '", type: File, contents: HelloWorld, Ensure: present}' | dsc resource set -r 'PSDesiredStateConfiguration/File'
$LASTEXITCODE | Should -Be 0
Get-Content -Raw -Path $testFile | Should -Be "HelloWorld"
}

It 'Get works on traditional "Script" resource' -Skip:(!$IsWindows){

$testFile = "$testdrive\test.txt"
Expand Down
18 changes: 8 additions & 10 deletions powershell-adapter/psDscAdapter/win_psDscAdapter.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,15 @@ function Invoke-DscOperation {
$invokeResult = Invoke-DscResource -Method $Operation -ModuleName $cachedDscResourceInfo.ModuleName -Name $cachedDscResourceInfo.Name -Property $property

if ($invokeResult.GetType().Name -eq 'Hashtable') {
$invokeResult.keys | ForEach-Object -Begin { $getDscResult = @{} } -Process { $getDscResult[$_] = $invokeResult.$_ }
$invokeResult.keys | ForEach-Object -Begin { $ResultProperties = @{} } -Process { $ResultProperties[$_] = $invokeResult.$_ }
}
else {
# the object returned by WMI is a CIM instance with a lot of additional data. only return DSC properties
$invokeResult.psobject.Properties.name | Where-Object { 'CimClass', 'CimInstanceProperties', 'CimSystemProperties' -notcontains $_ } | ForEach-Object -Begin { $getDscResult = @{} } -Process { $getDscResult[$_] = $invokeResult.$_ }
$invokeResult.psobject.Properties.name | Where-Object { 'CimClass', 'CimInstanceProperties', 'CimSystemProperties' -notcontains $_ } | ForEach-Object -Begin { $ResultProperties = @{} } -Process { $ResultProperties[$_] = $invokeResult.$_ }
}

# set the properties of the OUTPUT object from the result of Get-TargetResource
$addToActualState.properties = $getDscResult
$addToActualState.properties = $ResultProperties
}
catch {
'ERROR: ' + $_.Exception.Message | Write-DscTrace
Expand Down Expand Up @@ -422,21 +422,19 @@ function Invoke-DscOperation {

# morph the INPUT object into a hashtable named "property" for the cmdlet Invoke-DscResource
$DesiredState.properties.psobject.properties | ForEach-Object -Begin { $property = @{} } -Process { $property[$_.Name] = $_.Value }

# using the cmdlet from PSDesiredStateConfiguration module in Windows
try {
$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 )

if ($getResult.GetType().Name -eq 'Hashtable') {
$getResult.keys | ForEach-Object -Begin { $getDscResult = @{} } -Process { $getDscResult[$_] = $getResult.$_ }
$invokeResult = Invoke-DscResource -Method $Operation -ModuleName $cachedDscResourceInfo.ModuleName -Name $cachedDscResourceInfo.Name -Property $property
if ($invokeResult.GetType().Name -eq 'Hashtable') {
$invokeResult.keys | ForEach-Object -Begin { $ResultProperties = @{} } -Process { $ResultProperties[$_] = $invokeResult.$_ }
}
else {
# the object returned by WMI is a CIM instance with a lot of additional data. only return DSC properties
$getResult.psobject.Properties.name | Where-Object { 'CimClass', 'CimInstanceProperties', 'CimSystemProperties' -notcontains $_ } | ForEach-Object -Begin { $getDscResult = @{} } -Process { $getDscResult[$_] = $getResult.$_ }
$invokeResult.psobject.Properties.name | Where-Object { 'CimClass', 'CimInstanceProperties', 'CimSystemProperties' -notcontains $_ } | ForEach-Object -Begin { $ResultProperties = @{} } -Process { $ResultProperties[$_] = $invokeResult.$_ }
}

# set the properties of the OUTPUT object from the result of Get-TargetResource
$addToActualState.properties = $getDscResult
$addToActualState.properties = $ResultProperties
}
catch {
'ERROR: ' + $_.Exception.Message | Write-DscTrace
Expand Down