我試圖在以下C#代碼中執行_Get-User -Identity "John Doe" | FL_
命令。在C#中執行Powershell命令(get-user -Identity「John Doe」| FL)
PowerShell powershell = PowerShell.Create();
powershell.AddCommand("get-user");
powershell.AddParameter("Identity", UserName.Text);
try
{
runspace.Open();
powershell.Runspace = runspace;
Collection<PSObject> results = powershell.Invoke();
var builder = new StringBuilder();
foreach (var psObject in results)
{
builder.AppendLine(psObject.ToString() + "\r\n");
}
ResultBox.Text = Server.HtmlEncode(builder.ToString());
}
在哪裏添加_FL_
命令?
難道那只是將'results'傳遞給「FL」(一個不同的Powershell命令)嗎?或者,也許你可以使用完整的命令字符串? – 2011-11-09 18:39:09