C# Powershell runspace available across methods -



C# Powershell runspace available across methods -

quick question regarding powershell invokes within c#

i'd able inquire c# load powershell module in separate method, run powershell commands in method.

currently (limited) knowledge of invoking ps in c#, looks cant access powershell instance method - correct?

code illustration below. i'm looking usind runspaces, did not want fire much time researching either.

any help in best way access powershell instance (with module loaded) other methods within class appreciated.

namespace test { public class test { public void loadmodule() { using (powershell powershellinstance = powershell.create()) { powershellinstance.addscript("add-pssnapin vmware.vimautomation.core"); powershellinstance.invoke(); if (powershellinstance.streams.error.count > 0) { infobox.text = "error loading snapin"; return; } else { infobox.text = "loaded"; } powershellinstance.commands.clear(); } } public void someothermethod() { //do more powershell - without loading module }

c# powershell

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -