【发布时间】:2021-09-30 18:54:56
【问题描述】:
我有一个简单的 WPF 表单,我希望将某个 powershell 脚本的输出写入 Visual Studio 输出。但是,我在 Visual Studio 中没有得到正确的输出。
Powershell:
nmap -O 198.168.1.1/24
我现在有一个只有一个按钮的 wpf 表单,代码如下:
MainWindow.xaml.cs:
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Debug.WriteLine("I am Here!");
PowerShell ps = PowerShell.Create();
ps.AddScript(@"C:\Research\Network Scanner\powerscript.ps1");
Collection<PSObject> resultsN = null;
resultsN = ps.Invoke();
Debug.WriteLine(resultsN);
// ps.Invoke();
}
}
}
输出:
我在这里!
线程 0x4378 已退出,代码为 0 (0x0)。 System.Collections.ObjectModel.Collection`1[System.Management.Automation.PSObject]
【问题讨论】:
标签: c# powershell