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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.