Skip to content

Commit

Permalink
win_powershell - Add defensive GetType() check (#710)
Browse files Browse the repository at this point in the history
Some unique types may fail when calling the GetType() method. This
commit adds a check to ensure the GetType() method exists before calling
it to avoid an error when trying to process the output object.
  • Loading branch information
jborean93 authored Dec 11, 2024
1 parent b6172c3 commit 6fd01d3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions changelogs/fragments/win_powershell-type.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion plugins/modules/win_powershell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 6fd01d3

Please sign in to comment.