2

I want to connect to a remote powershell session and load modules in the runspace.

I got the connection part using this link :- Create remote powershell session in c#?

How do I load the modules in the runspace and call other commands in that module ?

Thank you.

Community
  • 1
  • 1
RDs
  • 513
  • 6
  • 22

1 Answers1

1

RunspaceFactory.CreateRunspace() has an overload that accepts an InitialSessionState object. An InitialSessionState object has a Modules property which holds a collection of modules. You can add modules there and they'll be loaded when the runspace is opened.

Alternatively, you can just invoke Import-Module in the pipeline.

briantist
  • 45,546
  • 6
  • 82
  • 127