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 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.