件名が平凡すぎるように見え、そのような質問に対処する投稿が多数あることは理解しています。私が探していたものが見つからなかったので、この投稿をしました。
リモート マシン (マシン B) で実行されるように、マシン A から powershell ファイルを呼び出しています。
// コード スニペットは次のとおりです。
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
string scripttext = "$secpasswd = ConvertTo-SecureString '222_bbbb' -AsPlainText –Force";
string scripttext1 = "$mycreds = New-object -typename System.Management.Automation.PSCredential('TS-TEST-09\\Administrator',$secpasswd)";
string scripttext2 = "$s = New-PSSession -ComputerName TS-TEST-09 -Credential $mycreds";
**string scripttext5 = "Invoke-Command -Session $s -FilePath 'helper.ps1' | out-null";**
pipeline.Commands.AddScript(scripttext);
pipeline.Commands.AddScript(scripttext1);
pipeline.Commands.AddScript(scripttext2);
pipeline.Commands.AddScript(scripttext5);
Collection<PSObject> results = pipeline.Invoke();
現在行内 string scripttext5 = "Invoke-Command -Session $s -FilePath 'helper.ps1' | out-null"; 処理のために、いくつかのパラメーター (たとえば、c# 環境のユーザー名: useralias) をこの helper.ps1 ファイルに渡す必要があります。誰かがそうする正しい方法に私を導くことができますか?
TIA、マニッシュ