C# から Enter-PSsession を使用して、Powershell リモート処理を有効にしてリモートでコマンドを実行しようとしています。ここにコードがあります
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();
CmdletInvocationException が発生します。同内容の詳細はこちら。
System.Management.Automation.CmdletInvocationException が処理されませんでした Message=メソッドまたは操作が実装されていません。Source=System.Management.Automation WasThrownFromThrowStatement=false StackTrace: > System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(オブジェクト入力、ハッシュ テーブル エラー結果、ブール値列挙) で System.Management.Automation.Internal.PipelineProcessor.SynchronousExecute(配列入力) 、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: システム。Management.Automation.PSNotImplementedException Message=メソッドまたは操作が実装されていません。Source=System.Management.Automation StackTrace: at > System.Management.Automation.Internal.Host.InternalHost.GetIHostSupportsInteractiveSession() at > System.Management.Automation.Internal.Host.InternalHost.PushRunspace(Runspace runspace) at Microsoft.PowerShell. Commands.EnterPSSessionCommand.ProcessRecord() で System.Management.Automation.Cmdlet.DoProcessRecord() で System.Management.Automation.CommandProcessor.ProcessRecord() InnerException:
PowerShell から直接 Enter-PSsession を試すと、問題なくリモート セッションを開始できます... C# コードの何が問題なのか、誰でもアドバイスできますか