From d5a0c18170af40b1b88293a18b4bdcd70b3d7d25 Mon Sep 17 00:00:00 2001 From: Trond Hindenes Date: Thu, 10 Jul 2014 12:00:00 +0200 Subject: [PATCH] Better result handling --- library/windows/win_feature.ps1 | 34 ++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/library/windows/win_feature.ps1 b/library/windows/win_feature.ps1 index 522cced33bc..a0776a4bf1a 100644 --- a/library/windows/win_feature.ps1 +++ b/library/windows/win_feature.ps1 @@ -92,23 +92,31 @@ Elseif ($state -eq "absent") { # Loop through results and create a hash containing details about # each role/feature that is installed/removed $installed_features = @() -ForEach ($item in $featureresult.FeatureResult) { - $installed_features += New-Object psobject @{ - id = $item.id.ToString() - display_name = $item.DisplayName - message = $item.Message.ToString() - restart_needed = $item.RestartNeeded.ToString() - skip_reason = $item.SkipReason.ToString() - success = $item.Success.ToString() +#$featureresult.featureresult is filled if anything was changed +if ($featureresult.FeatureResult) +{ + ForEach ($item in $featureresult.FeatureResult) { + $installed_features += New-Object psobject @{ + id = $item.id.ToString() + display_name = $item.DisplayName + message = $item.Message.ToString() + restart_needed = $item.RestartNeeded.ToString() + skip_reason = $item.SkipReason.ToString() + success = $item.Success.ToString() + } } + Set-Attr $result "feature_result" $installed_features + + + $result.changed = $true +} +Else +{ + Set-Attr $result "feature_result" $null } -Set-Attr $result "feature_result" $installed_features + Set-Attr $result "feature_success" $featureresult.Success.ToString() Set-Attr $result "feature_exitcode" $featureresult.ExitCode.ToString() Set-Attr $result "feature_restart_needed" $featureresult.RestartNeeded.ToString() -If ($result.feature_result.Length -gt 0) { - $result.changed = $true -} - Exit-Json $result;