Ansible Windows Powershell over SSH not accepting pipelined input

I’m currently running into a problem with with the way the exec_wrapper receives commands/scripts to run. I’m trying to run the below on ansible core 2.16.3, I have also tried on ansible core 2.18.7 but I’m getting the same error.

The connection I’m performing goes like this:

My laptop --(SSH)-> CyberArk --(SSH)-> my_windows_server

The ansible.cfg file contains the following:

[ssh_connection]
gather_timeout = 90
pipelining = true
ssh_args = -o ControlMaster=auto -o ControlPersist=60s

My inventory file looks like this:

all:
  vars:
    ansible_connection: ssh
    ansible_shell_type: powershell
  hosts:
    my_windows_server:

ftp:
  hosts:
    my_windows_server:

My playbook looks like this:

---
- name: Configure Windows Firewall
  hosts: ftp
  gather_facts: no
  tasks:
      # Test connectivity to a windows host
      # ansible winserver -m ansible.windows.win_ping

    - name: Execute whoami in PowerShell
      ansible.windows.win_shell: "whoami"

I turned on powershell transcription on the server and managed to get the script being run, which looks like this and seems fairly normal based on what I have been able to piece together:

&chcp.com 65001 > $null
if ($PSVersionTable.PSVersion -lt [Version]"3.0") {
'{"failed":true,"msg":"Ansible requires PowerShell v3.0 or newer"}'
exit 1
}
$exec_wrapper_str = $input | Out-String
$split_parts = $exec_wrapper_str.Split(@("`0`0`0`0"), 2, [StringSplitOptions]::RemoveEmptyEntries)
If (-not $split_parts.Length -eq 2) { throw "invalid payload" }
Set-Variable -Name json_raw -Value $split_parts[1]
$exec_wrapper = [ScriptBlock]::Create($split_parts[0])
&$exec_wrapper

However that is followed by the following error which is the same error I see in the ansible output:

PS>CommandInvocation(Out-String): "Out-String"
>> ParameterBinding(Out-String): name="InputObject"; value="Exception calling "Create" with "1" argument(s): "At line:159 char:5
+     {"module_entry": "IyFwb3dlcnNoZWxsCgojIENvcHlyaWdodDogKGMpIDIwMTc ...
+     ~
Unexpected token '{' in expression or statement.""
Exception calling "Create" with "1" argument(s): "At line:159 char:5
+     {"module_entry": "IyFwb3dlcnNoZWxsCgojIENvcHlyaWdodDogKGMpIDIwMTc ...
+     ~
Unexpected token '{' in expression or statement."
At line:10 char:1
+ $exec_wrapper = [ScriptBlock]::Create($split_parts[0])
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ParseException
Exception calling "Create" with "1" argument(s): "At line:159 char:5
+     {"module_entry": "IyFwb3dlcnNoZWxsCgojIENvcHlyaWdodDogKGMpIDIwMTc ...
+     ~
Unexpected token '{' in expression or statement."
At line:10 char:1
+ $exec_wrapper = [ScriptBlock]::Create($split_parts[0])
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ParseException
Exception calling "Create" with "1" argument(s): "At line:159 char:5
+     {"module_entry": "IyFwb3dlcnNoZWxsCgojIENvcHlyaWdodDogKGMpIDIwMTc ...
+     ~
Unexpected token '{' in expression or statement."
At line:10 char:1
+ $exec_wrapper = [ScriptBlock]::Create($split_parts[0])
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ParseException

windows ssh powershell