@@ -46,9 +46,7 @@ if ($Operation -eq 'ClearCache') {
46
46
}
47
47
48
48
if (' Validate' -ne $Operation ) {
49
- # write $jsonInput to STDERR for debugging
50
- $trace = @ {' debug' = ' jsonInput=' + $jsonInput } | ConvertTo-Json - Compress
51
- $host.ui.WriteErrorLine ($trace )
49
+ Write-DscTrace - Operation Debug - Message " jsonInput=$jsonInput "
52
50
53
51
# load private functions of psDscAdapter stub module
54
52
if ($PSVersionTable.PSVersion.Major -le 5 ) {
@@ -135,16 +133,14 @@ switch ($Operation) {
135
133
{ @ (' Get' , ' Set' , ' Test' , ' Export' ) -contains $_ } {
136
134
$desiredState = $psDscAdapter.invoke ( { param ($jsonInput ) Get-DscResourceObject - jsonInput $jsonInput }, $jsonInput )
137
135
if ($null -eq $desiredState ) {
138
- $trace = @ {' debug' = ' ERROR: Failed to create configuration object from provided input JSON.' } | ConvertTo-Json - Compress
139
- $host.ui.WriteErrorLine ($trace )
136
+ Write-DscTrace - Operation Error - message ' Failed to create configuration object from provided input JSON.'
140
137
exit 1
141
138
}
142
139
143
140
# only need to cache the resources that are used
144
141
$dscResourceModules = $desiredState | ForEach-Object { $_.Type.Split (' /' )[0 ] }
145
142
if ($null -eq $dscResourceModules ) {
146
- $trace = @ {' debug' = ' ERROR: Could not get list of DSC resource types from provided JSON.' } | ConvertTo-Json - Compress
147
- $host.ui.WriteErrorLine ($trace )
143
+ Write-DscTrace - Operation Error - Message ' Could not get list of DSC resource types from provided JSON.'
148
144
exit 1
149
145
}
150
146
@@ -162,21 +158,28 @@ switch ($Operation) {
162
158
}
163
159
}
164
160
161
+ $inDesiredState = $true
165
162
foreach ($ds in $desiredState ) {
166
163
# process the INPUT (desiredState) for each resource as dscresourceInfo and return the OUTPUT as actualState
167
164
$actualState = $psDscAdapter.invoke ( { param ($op , $ds , $dscResourceCache ) Invoke-DscOperation - Operation $op - DesiredState $ds - dscResourceCache $dscResourceCache }, $Operation , $ds , $dscResourceCache )
168
165
if ($null -eq $actualState ) {
169
- $trace = @ {' debug' = ' ERROR: Incomplete GET for resource ' + $ds.Name } | ConvertTo-Json - Compress
170
- $host.ui.WriteErrorLine ($trace )
166
+ Write-DscTrace - Operation Error - Message ' Incomplete GET for resource ' + $ds.Name
171
167
exit 1
172
168
}
169
+ if ($null -ne $actualState.Properties -and $actualState.Properties.InDesiredState -eq $false ) {
170
+ $inDesiredState = $false
171
+ }
173
172
$result += $actualState
174
173
}
175
174
176
175
# OUTPUT json to stderr for debug, and to stdout
177
- $result = @ { result = $result } | ConvertTo-Json - Depth 10 - Compress
178
- $trace = @ {' debug' = ' jsonOutput=' + $result } | ConvertTo-Json - Compress
179
- $host.ui.WriteErrorLine ($trace )
176
+ if ($Operation -eq ' Test' ) {
177
+ $result = @ { result = $result ; _inDesiredState = $inDesiredState } | ConvertTo-Json - Depth 10 - Compress
178
+ }
179
+ else {
180
+ $result = @ { result = $result } | ConvertTo-Json - Depth 10 - Compress
181
+ }
182
+ Write-DscTrace - Operation Debug - Message " jsonOutput=$result "
180
183
return $result
181
184
}
182
185
' Validate' {
0 commit comments