【发布时间】:2019-09-14 16:25:03
【问题描述】:
我想从 PowerShell cmdlet Get-NetConnectionProfile 获取所有详细信息,但它没有在文本框中显示,我也不知道为什么。
我尝试了其他“get”cmdlet,例如Get-NetAdapter,效果很好。
我可以看到文本框中的所有内容。
ProcessStartInfo psi = new ProcessStartInfo("powershell");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.CreateNoWindow = true;
psi.RedirectStandardInput = true;
var proc = Process.Start(psi);
proc.StandardInput.WriteLine("Get-NetConnectionProfile");
proc.StandardInput.WriteLine(@"exit");
string s = proc.StandardOutput.ReadToEnd();
TxtIp.Text = s;
【问题讨论】:
-
这不是从 C# 使用 PowerShell 的好方法。您应该使用 PowerShell 类而不是尝试在单独的进程中运行您的命令。
-
Get-NetConnectionProfile 是否在 PowerShell 中工作?你期望什么输出?您可能需要通过管道传输结果
-
通过“所有详细信息”,我假设您指的是运行 Get-NetConnectionProfile 时看到的默认输出。看到我的答案,让我知道
标签: c# powershell