Skip to content

Commit b84c52e

Browse files
author
Steve Lee (POWERSHELL HE/HIM) (from Dev Box)
committed
move check for errors to before being disposed
1 parent 919567d commit b84c52e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

resources/PSScript/psscript.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ try {
135135
$outputCollection = $ps.EndInvoke($asyncResult)
136136
write-traces
137137

138+
if ($ps.HadErrors) {
139+
# If there are any errors, we will exit with an error code
140+
Write-DscTrace -Now -Level Error -Message 'Errors occurred during script execution.'
141+
exit 1
142+
}
143+
138144
foreach ($output in $outputCollection) {
139145
$outputObjects.Add($output)
140146
}
@@ -147,12 +153,6 @@ finally {
147153
$ps.Dispose()
148154
}
149155

150-
if ($ps.HadErrors) {
151-
# If there are any errors, we will exit with an error code
152-
Write-DscTrace -Now -Level Error -Message 'Errors occurred during script execution.'
153-
exit 1
154-
}
155-
156156
# Test should return a single boolean value indicating if in the desired state
157157
if ($Operation -eq 'Test') {
158158
if ($outputObjects.Count -eq 1 -and $outputObjects[0] -is [bool]) {

0 commit comments

Comments
 (0)