diff --git a/lib/ansible/module_utils/powershell.ps1 b/lib/ansible/module_utils/powershell.ps1 index 3c58b210d8..c6df6d5c76 100644 --- a/lib/ansible/module_utils/powershell.ps1 +++ b/lib/ansible/module_utils/powershell.ps1 @@ -98,6 +98,46 @@ Function Fail-Json($obj, $message = $null) Exit 1 } +# Helper function to add warnings, even if the warnings attribute was +# not already set up. This is a convenience for the module developer +# so he does not have to check for the attribute prior to adding. +Function Add-Warning($obj, $message) +{ + if (Get-Member -InputObject $obj -Name "warnings") { + if ($obj.warnings -is [System.Array]) { + $obj.warnings += $message + } else { + throw "warnings attribute is not an array" + } + } else { + $obj.warnings = ,@( $message ) + } +} + +# Helper function to add deprecations, even if the deprecations attribute was +# not already set up. This is a convenience for the module developer +# so he does not have to check for the attribute prior to adding. +Function Add-DeprecationWarning($obj, $message, $version = $null) +{ + if (Get-Member -InputObject $obj -Name "deprecations") { + if ($obj.deprecations -is [System.Array]) { + $obj.deprecations += @{ + msg = $message + version = $version + } + } else { + throw "deprecations attribute is not a list" + } + } else { + $obj.deprecations = ,@( + @{ + msg = $message + version = $version + } + ) + } +} + Function Expand-Environment($value) { [System.Environment]::ExpandEnvironmentVariables($value)