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.
RunspaceFactory.CreateRunspace()has an overload that accepts anInitialSessionStateobject. AnInitialSessionStateobject has aModulesproperty 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-Modulein the pipeline.