c# - Opening runspaces multiple times -


i want execute powershell command on remote computer c#. have achieved same using

    public collection<psobject> runscript(string command)     {         collection<psobject> results = null;         using (var powershell = powershell.create())         {          runspace runspace = runspacefactory.createrunspace(connection);          runspace.open();          powershell.runspace = runspace();           powershell.addscript(command);           results = powershell.invoke();           runspace.close();       }             return results;         }     } 

i able execute first time. when try executr function second time gives me error, runspace closed.actually did close @ last why doesnt reopen when function called.

you closed didn't dispose of it:

using (var powershell = powershell.create()) using (runspace runspace = runspacefactory.createrunspace(connection)) {     runspace.open();     powershell.runspace = runspace();     powershell.addscript(command);     results = powershell.invoke();     runspace.close(); } 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -