C# PowerShell Remoting issue: method or operation not implemented -
i have problem c# code invokes command on other computer using powershell. when enter powershell, works fine, when try invoke using c# ui application, throws exception method or operation not implemented.
here code:
command cmd = new command(@".\remoteschedule.ps1"); //determine if there computer name or ip address if (char.isdigit(cbomachine.text.tostring().firstordefault())) cmd.parameters.add("computername", cboschedulemachine.text); else cmd.parameters.add("computername", cboschedulemachine.text + "." + configurationmanager.appsettings["domain"]); cmd.parameters.add("username", @txtscheduleusername.text); cmd.parameters.add("password", txtschedulepassword.text); cmd.parameters.add("taskname", "\"" + txtscheduletaskname.text + "\""); cmd.parameters.add("command", "\"" + @txtschedulecommand.text + "\""); cmd.parameters.add("arguments", "\"" + txtschedulearguments.text + "\""); cmd.parameters.add("startdate", dpkschedulestartdate.selecteddate.value.tostring("mm-dd-yyyy")); cmd.parameters.add("starttime", txtschedulestarttime.text); cmd.parameters.add("workingdirectory", "\"" + @txtworkingfolder.text + "\""); cmd.parameters.add("run", chkschedulerun.ischecked); pipeline.commands.add(cmd); // execute script collection<psobject> results = pipeline.invoke(); runspace.close(); stringbuilder stringbuilder = new stringbuilder(); foreach (psobject obj in results) { stringbuilder.appendline(datetime.now.tostring() + ": "); stringbuilder.appendline(obj.tostring()); } txtscheduleoutput.selectionstart = 0; txtscheduleoutput.text = stringbuilder.tostring();
and here part of powershell script handles parameters:
param( [string]$computername = $(throw "missing parameter computername"), [string]$username = $(throw "missing parameter username"), [string]$password = $(throw "missing parameter password"), [string]$taskname = $(throw "missing parameter taskname"), [string]$command = $(throw "missing parameter command"), [string]$arguments = $(throw "missing parameter arguments"), [datetime]$startdate = $(throw "missing parameter startdate"), [string]$starttime = $(throw "missing parameter starttime"), [string]$workingdirectory = $(throw "missing parameter workingdirectory"), [bool]$run = $(throw "missing parameter run") )
help, please! thanks!
if i'm understanding correctly, you're invoking command on remote machine. however, you're using file containing command. when invoke gets called, it's trying find .\remoteschedule.ps1
on remote system, , failing miserably.
trivial solution ensure remoteschedule.ps1 on drive systems can access, , make sure executionpolicy set allow unsigned scripts.
non-trivial rewrite entire script in script (like scriptblock), , invoke instead of file directly.
Comments
Post a Comment