c# 4.0 - Powershell v3 Remoting from C# using Enter-PSsession -


i trying use enter-pssession c# enable , use powershell remoting run commands remotely. here code

runspace remoterunspace = runspaces.runspacefactory.createrunspace(); remoterunspace.open(); powershell.runspace = remoterunspace; pscommand command = new pscommand(); command.addcommand("enter-pssession"); command.addparameter("computername", "remotehostname"); command.addparameter("credential", vmmcredential); powershell.commands = command; powershell.invoke(); 

i cmdletinvocationexception. here details same.

system.management.automation.cmdletinvocationexception unhandled message=the method or operation not implemented. source=system.management.automation wasthrownfromthrowstatement=false stacktrace: @ > system.management.automation.internal.pipelineprocessor.synchronousexecuteenumerate(object input, hashtable errorresults, boolean enumerate) @ system.management.automation.internal.pipelineprocessor.synchronousexecute(array input, hashtable errorresults) @ system.management.automation.internal.pipelineprocessor.execute(array input) @ system.management.automation.internal.pipelineprocessor.execute() @ system.management.automation.runspaces.localpipeline.invokehelper() @ system.management.automation.runspaces.localpipeline.invokethreadproc() innerexception: system.management.automation.psnotimplementedexception message=the method or operation not implemented. source=system.management.automation stacktrace: @ > system.management.automation.internal.host.internalhost.getihostsupportsinteractivesession() @ > system.management.automation.internal.host.internalhost.pushrunspace(runspace runspace) @ microsoft.powershell.commands.enterpssessioncommand.processrecord() @ system.management.automation.cmdlet.doprocessrecord() @ system.management.automation.commandprocessor.processrecord() innerexception:

if try enter-pssession directly powershell able start remote session no issues... can advice wrong in c# code

ok not able enter-pssession cmdlet c# code below code able use ps remoting using c#...

int iremoteport = 5985; string strshelluri = @"http://schemas.microsoft.com/powershell/microsoft.powershell"; string strappname = @"/wsman"; authenticationmechanism auth = authenticationmechanism.negotiate;  wsmanconnectioninfo ci = new wsmanconnectioninfo(     false,     sremote,     iremoteport,     strappname,     strshelluri,     creds); ci.authenticationmechanism = auth;  runspace runspace = runspacefactory.createrunspace(ci); runspace.open();  powershell psh = powershell.create(); psh.runspace = runspace; 

you can use psh run commands remotely.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -