【问题标题】:C# Powershell Script Not Writing to Output in Visual StudioC# Powershell 脚本未写入 Visual Studio 中的输出
【发布时间】: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


    【解决方案1】:

    这会有所帮助。 foreach(结果中的 PSObject obj) { Debug.WriteLine(obj.ToString()); }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-11
      • 2012-06-27
      • 2015-09-01
      • 1970-01-01
      • 2012-05-01
      • 2022-01-10
      • 2023-03-24
      相关资源
      最近更新 更多