diff --git a/changelogs/fragments/win_powershell-type.yml b/changelogs/fragments/win_powershell-type.yml new file mode 100644 index 00000000..bb507fa4 --- /dev/null +++ b/changelogs/fragments/win_powershell-type.yml @@ -0,0 +1,4 @@ +bugfixes: + - >- + ansible.windows.win_powershell - Add extra checks to avoid ``GetType`` error when converting the output object + - ttps://github.com/ansible-collections/ansible.windows/issues/708 diff --git a/plugins/modules/win_powershell.ps1 b/plugins/modules/win_powershell.ps1 index a4d3028b..80f854f8 100644 --- a/plugins/modules/win_powershell.ps1 +++ b/plugins/modules/win_powershell.ps1 @@ -363,7 +363,9 @@ Function Convert-OutputObject { elseif (&$isType -InputObject $InputObject -Type ([switch])) { $InputObject.IsPresent } - elseif ($InputObject.GetType().IsValueType) { + # Have a defensive check to see if GetType() exists as a method on the object. + # https://github.com/ansible-collections/ansible.windows/issues/708 + elseif ('GetType' -in $InputObject.PSObject.Methods.Name -and $InputObject.GetType().IsValueType) { # We want to display just this value and not any properties it has (if any). $InputObject.PSObject.BaseObject }