QuickTip: Posh-SSH module on Windows Server 2019

On several Windows 2019 servers I have already had the problem that the PowerShell module "Posh-SSH" only returns an error message when establishing an SSH connection. I had this problem with Windows Server 2019 and the Posh-SSH module in version 2.2. Here is a quick tip on how to fix the problem.

The error message is as follows:

New-SSHSession : The file or assembly "Renci.SshNet, Version=2016.1.0.0, Culture=neutral,
PublicKeyToken=1cee9f8bde3db106" or a dependency thereof was not found. The system cannot recognize the specified
file cannot be found.

QuickTip: Posh-SSH module on Windows Server 2019

The cause of this error is related to the file "Renci.SshNet.dll". Different programs have different versions of the DLL. The data backup software Veeam, for example, is one of these programs, and there are also several versions of the "Renci.SshNet.dll" file in the Windows directory.

The PowerShell module Posh-SSH seems to have problems with several versions of the DLL and the error mentioned above occurs. Posh-SSH also comes with a version of the Renci.SshNet.dll file. The file can be found in the directory "C:\Program Files\WindowsPowerShell\Modules\Posh-SSH\2.2\Assembly":

Renci.SshNet.dll

To fix the problem, Posh-SSH needs to load exactly this version of the file, so as a quick workaround, the file can be renamed. In this case I have renamed the file to "Renci.SshNet2.dll":

Renci.SshNet.dll

The new name of the file must now be entered in the PowerShell module file for Posh-SSH. The module file can be found under "C:\Program Files\WindowsPowerShell\Modules\Posh-SSH\2.2" and is called "Posh-SSH.psd1:

QuickTip: Posh-SSH module on Windows Server 2019

In this file, the name of the file "Renci.SshNet" can now be replaced with "Renci.SshNet2" using "Search and replace":

QuickTip: Posh-SSH module on Windows Server 2019

As soon as the PowerShell has been closed or the module has been reloaded, the SSH connections work again.

QuickTip: Posh-SSH module on Windows Server 2019

Perhaps this will help some of you.

If anyone has or had this problem and knows a more elegant method without having to change the module file, please let me know. The problem with this solution is that the changes have to be made again when the module is updated. It would therefore be nice if there was another solution.

2 thoughts on “QuickTipp: Posh-SSH Modul auf Windows Server 2019”

  1. Hi,

    je nachdem was du vorhast, könntest du ggfs. auf den mittlerweile als optionales Feature integrierten OpenSSH Client in Windows Server 2019 / Win 10 zurückgreifen.

    Viele Grüße
    Jan

    Reply

Leave a Comment