首先,请确保您在ASP.net页面中正确引用了Power Shell模块。
可以尝试使用以下Power Shell代码来执行命令并将输出复制到ASP.net文本框中:
string command = "你的Power Shell命令"; //将此处替换为您的Power Shell命令
PowerShell powerShell = PowerShell.Create();
powerShell.AddScript(command);
Collection
StringBuilder stringBuilder = new StringBuilder();
foreach (PSObject obj in PSOutput)
{
stringBuilder.AppendLine(obj.ToString());
}
TextBox1.Text = stringBuilder.ToString();
powerShell.Dispose();
还有一个可能的解决方案是使用Process类来执行Power Shell命令。以下是一个相关示例:
string command = "你的Power Shell命令";
Process process = new Process();
process.StartInfo.FileName = "powershell.exe";
process.StartInfo.Arguments = command;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
TextBox1.Text = process.StandardOutput.ReadToEnd();
process.WaitForExit();
process.Dispose();
希望这些解决方案可以帮助您在ASP.net中正确显示Power Shell命令的输出。