Powershell ssh command executing

Hi guys !

I need to send these commands through any powershell ssh module in order to return the correct version of the operating system based on the distribution.
If I open putty and paste the code, it works without problems, if I use any module (posh-ssh or others) when I send this command, the output is an error.
Can anyone tell me why?


$linuxhost = ''

$LNXver = @'
/bin/bash<arch=$(uname -m)
kernel=$(uname -r)
if [ -n "$(command -v lsb_release)" ];
then distroname=$(lsb_release -s -d)
elif [ -f "/etc/os-release" ]; 
then distroname=$(grep PRETTY_NAME /etc/os-release | sed 's/PRETTY_NAME=//g' | tr -d '="')
elif [ -f "/etc/debian_version" ]; 
then distroname="Debian $(cat /etc/debian_version)"
elif [ -f "/etc/redhat-release" ]; 
then distroname=$(cat /etc/redhat-release)
else distroname="$(uname -s) $(uname -r)"
echo "${distroname}"

$LNXver2 = (Invoke-SSHCommand -ComputerName $linuxhost -Command $LNXver).result