1

I'm using a linux docker image with powershell and few modules installed on it. Programmatically, my code do not see the modules.

For verification, if I start the image and instanciate powershell, I can run commands and confirm that the modules are installed: kubectl run -i --tty test --image=urlofimage:20211008.8 --command pwsh

However, my code do not see the modules. The extract of code below works in a windows machine, but returns the following error in the docker image:

This parameter set requires WSMan, and no supported WSMan client library was found. WSMan is either not installed or unavailable for this system.

 internal const string NewSessionScript = "New-PSSession -ConfigurationName:Microsoft.Exchange -Authentication:Basic -ConnectionUri:{0} -Credential $cred -AllowRedirection";
 this._runspace.SetCredential(userName, password);           
 var command = new PSCommand();
 command.AddScript(string.Format(NewSessionScript, connectionUri));
 var result = this._runspace.ExecuteCommand<PSSession>(command);

Question: It looks like the code is instanciating powershell "in memory" but does not use the powershell that is installed on the machine. How can I use it and leverage an image with all my powershell dependancies installed?

CloudAnywhere
  • 669
  • 1
  • 11
  • 27
  • Have you tried [following the instructions in the error message](https://stackoverflow.com/a/67792872/712649)? – Mathias R. Jessen Oct 11 '21 at 09:26
  • yes, as I said powershell and dependancies are correctly installed. If I start the image and start the commands in it, it works. It is the powershell instanciation by code that does not use the powershell "instance" installed on the OS – CloudAnywhere Oct 11 '21 at 09:41
  • And which package (and version) are you using to reference PowerShell/System.Management.Automation in your code? – Mathias R. Jessen Oct 11 '21 at 09:47
  • System.management.automation v 7.0.3 Microsoft.powershell.Commands.Diagnostics 7.0.3 Microsoft.powershell.Commands.Management 7.0.3 Microsoft.powershell.Commands.Utility 7.0.3 Microsoft.powershell.ConsoleHost 7.0.3 Microsoft.powershell.Native 7.0.0 Microsoft.powershell.SDK 7.0.3 Microsoft.powershell.Security 7.0.3 – CloudAnywhere Oct 11 '21 at 12:57

0 Answers0