'Using com.jcraft.jsch to execute script on powershell not working properly

I can execute powershell commands remotly using com.jcraft.jsch but when I try to call ps1 file which contains below code it does not work properly. Get-WindowsFeature return results but "ForEach-Object" or "Where-Object" do not return result and error. Over console it works properly. The problem must be caused by "com.jcraft.jsch" but I could not resolve it.

ssh over console works fine

ps1 command

jsch result is empty

#test-1.ps1
Get-WindowsFeature | ForEach-Object {Write-Host $_.Name}

#test-2.ps1
$RequiredWindowsFeatures = @("Web-Asp-Net45", "NET-Framework-45-Features");
foreach ($RequireFeature in $RequiredWindowsFeatures) {
    $Feature = Get-WindowsFeature | Where-Object { $PSItem.Name -like ($RequireFeature + "*") };
    if (-not ($Feature.Installed -eq $true)) {
        [console]::WriteLine("");
        #return;
    }
}


Solution 1:[1]

$ProgressPreference = 'SilentlyContinue'

After I close progess bar of powershell, it works fine.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 yavuz yasin CELIK