I want to put the name of an existing interface in Linux into a variable so that I can use it using the variable. this is my source:
Write-Output "⚙ Detecting Linux network interface..."
$nicName = Invoke-VMScript -VM $vm -ScriptText "ip -o link show | awk -F': ' '{print `$2}' | grep -v '^lo'" -GuestUser "root" -GuestPassword $pass -ScriptType Bash
$nicNameString = ($nicName.ScriptOutput.Split("`n")[0]).Trim() -replace "`r",""
Write-Output "⚙ Setting IP for Linux VM on interface $nicNameString..."
$scriptLinux = @"
cat <<EOF > /etc/netplan/*.yaml
network:
version: 2
ethernets:
${nicNameString}:
dhcp4: no
addresses: [$IP/24]
gateway4: $gateway
nameservers:
addresses: [8.8.8.8,1.1.1.1]
EOF
netplan apply
systemctl enable ssh
systemctl restart ssh
I tried this command in PowerShell, but the output was as follows:

But I expected my output to be replaced with ens160 which is the original name of the interface. Can you see my problem and guide me?
Because the interface names are different in different Linux distributions, I need to find it automatically and I can't enter a specific interface name.
/etc/netplan/*or/etc/network/interfacesor/etc/sysconfig/network-scripts/ifcfg*?