Powershell オブジェクトを使用して foreach ループを実行し、結果を取得します。
2 つの正しい IP アドレスの結果 144.68.205.19 と 144.68.205.22 を取得しましたが、1 行で出力されました。
144.68.205.19144.68.205.22
このように改行するはずだったのですが、
144.68.205.19
144.68.205.22
アドバイスしてください、ここでC#コード、
// Powershell
Runspace runSpace = RunspaceFactory.CreateRunspace();
runSpace.Open();
Pipeline pipeline = runSpace.CreatePipeline();
Command invokeScript = new Command("Invoke-Command");
RunspaceInvoke invoke = new RunspaceInvoke();
// invoke-command -computername compName -scriptblock { get-process }
ScriptBlock sb = invoke.Invoke("{"+ PowerShellCodeBox.Text +"}")[0].BaseObject as ScriptBlock;
invokeScript.Parameters.Add("scriptBlock", sb);
invokeScript.Parameters.Add("computername", TextBoxServer.Text);
string str = "";
pipeline.Commands.Add(invokeScript);
Collection<PSObject> output = pipeline.Invoke();
foreach (PSObject psObject in output)
{
str = str + psObject;
}
if (str == ""){
str = "Error";
ResultBox.ForeColor = System.Drawing.ColorTranslator.FromHtml("#FF0000");
}
ResultBox.Text = str;