0

when I work in remote-ssh to a Windows 2019 server (from Win10 client), if I need to run PowerShell commands that need to import a module, the command fails. If I run the same commands in Win10 or when logged on directly onto the Windows server all is good. This is one of those commands:

Get-ADComputer -Filter { (Enabled -eq $True) } -SearchBase $GsearchBaseOU

The error says: Get-ADComputer : Unable to contact the server. This may be because this server does not exist, it is currently down, or it does not have the Active Directory Web Services running. But it is misleading and the problem seems to be that the ActiveDirectory module does not load. I tried loading it manually when in remote-ssh but it doesn't, and no error is thrown. Anybody experiencing the same? Any special config needed in VS Code maybe?

UPDATE: loading the module when connected with putty works. Executing commands as a consequence also works. As I suspect, the problem is with the remote-ssh plugin in VS Code. Anybody experiencing the same?

UPDATE2: by running:

ssh -T -D 64971 -F "C:\Users\[redacted]\.ssh\config" serverName powershell

in a simple cmd prompt, I successfully login, but when I run the PowerShell command above (or any cmd-let that requires to import a module) I have the same results. So it is not a remote-ssh plugin issue. I have removed vs code by doing an in-depth removal, reinstalled everything, reconfigured and I get the same result. On a different machine I configured vs code with remote-ssh and configured ssh access to the same server but without using a config file. So, I have to enter the password everytime I move from one workspace to another. And that works! It seems that by using a ssh config file with keyfile causes the problem, but I don't see how it could be...

sigfried
  • 49
  • 1
  • 6
  • That error implies it's trying to run the command locally, not on the remote server (it's the error you always receive when you can't contact the domain controller or it's not running ADWS). But make sure the modules are installed on the destination server for `AllUsers`. If you run `Get-Command -Module ActiveDirectory` this will confirm if the module is loaded. – Scepticalist Jan 06 '23 at 10:17
  • I would run putty and verify if it works in putty. A remote SSH can fail for three reasons 1) Do not have connection 2) Bad credentials 3) Encryption issue. Using putty will help us determine what is issue. Credential seems to be good since you can make connection on other machines. Error seems to indicate a connection issue. I would try from cmd.exe >Ping IP. Try both IP and machine name. In some cases name will work and IP will not. – jdweng Jan 06 '23 at 10:40
  • @Scepticalist ActiveDirectory module is installed on remote machine, as it has the Directory Services installed. Get-Command -Module ActiveDirectory from remote shows all modules even in remote-ssh. Still the error is thrown. It seems that from remote-ssh importing modules is an issue. – sigfried Jan 06 '23 at 16:10
  • @jdweng remote-ssh connection is established successfully. No issues with that. I can run code successfully. It is the importing of modules that fails when inside a remote-ssh connection. – sigfried Jan 06 '23 at 16:12
  • So commands do not work from PUTTY when connected using SSH. What this means is the PATH (or environment) when log into SSH is not correct. Just to verify that Directory Services work from PUTTY with same account using SSH? I'm trying to figure out if the issue is with the local machine or remote machine. If putty works than it seems like it is the local machine running PS. – jdweng Jan 06 '23 at 16:56
  • If Get-Command returns the commands in Remote-SSH then the module is imported. Regardless this seems a VS code issue rather than a Powershell one. – Scepticalist Jan 06 '23 at 18:21
  • loading the module when connected with putty works. Executing commands as a consequence also works. As I suspect, the problem is with the remote-ssh plugin in VS Code – sigfried Jan 07 '23 at 09:57
  • @Scepticalist no the module is not imported when in remote-ssh. And yes, exactly, it is a vc code plugin problem. – sigfried Jan 07 '23 at 10:00

0 Answers0