diff --git a/lib/ansible/modules/windows/win_command.ps1 b/lib/ansible/modules/windows/win_command.ps1 index 0c4d36da75..f2763d0295 100644 --- a/lib/ansible/modules/windows/win_command.ps1 +++ b/lib/ansible/modules/windows/win_command.ps1 @@ -159,14 +159,14 @@ $proc.WaitForExit() | Out-Null $result.rc = $proc.ExitCode -If ($result.rc -ne 0) { - $result.failed = $true -} - $end_datetime = [DateTime]::UtcNow $result.start = $start_datetime.ToString("yyyy-MM-dd hh:mm:ss.ffffff") $result.end = $end_datetime.ToString("yyyy-MM-dd hh:mm:ss.ffffff") $result.delta = $($end_datetime - $start_datetime).ToString("h\:mm\:ss\.ffffff") +If ($result.rc -ne 0) { + Fail-Json -obj $result -message "non-zero return code" +} + Exit-Json $result diff --git a/lib/ansible/modules/windows/win_msg.ps1 b/lib/ansible/modules/windows/win_msg.ps1 index 92ce049f0e..04cf80b2ba 100644 --- a/lib/ansible/modules/windows/win_msg.ps1 +++ b/lib/ansible/modules/windows/win_msg.ps1 @@ -56,7 +56,7 @@ $result.runtime_seconds = $stopwatch.Elapsed.TotalSeconds $result.sent_localtime = $endsend_at.Trim() if ($result.rc -ne 0 ) { - Fail-Json $result "$output" + Fail-Json -obj $result -message "$output" } Exit-Json $result diff --git a/lib/ansible/modules/windows/win_shell.ps1 b/lib/ansible/modules/windows/win_shell.ps1 index 3b1e2d163b..3e4f4dc441 100644 --- a/lib/ansible/modules/windows/win_shell.ps1 +++ b/lib/ansible/modules/windows/win_shell.ps1 @@ -168,14 +168,14 @@ $proc.WaitForExit() | Out-Null $result.rc = $proc.ExitCode -If ($result.rc -ne 0) { - $result.failed = $true -} - $end_datetime = [DateTime]::UtcNow $result.start = $start_datetime.ToString("yyyy-MM-dd hh:mm:ss.ffffff") $result.end = $end_datetime.ToString("yyyy-MM-dd hh:mm:ss.ffffff") $result.delta = $($end_datetime - $start_datetime).ToString("h\:mm\:ss\.ffffff") +If ($result.rc -ne 0) { + Fail-Json -obj $result -message "non-zero return code" +} + Exit-Json $result