简体   繁体   English

C# Powershell 脚本未写入 Visual Studio 中的输出

[英]C# Powershell Script Not Writing to Output in Visual Studio

I have a simple WPF Form where I want the output of a certain powershell script to be written to the Visual Studio Output.我有一个简单的 WPF 表单,我希望将某个 powershell 脚本的输出写入 Visual Studio 输出。 However, I'm not getting the right output in Visual Studio.但是,我没有在 Visual Studio 中获得正确的输出。

Powershell:电源外壳:

nmap -O 198.168.1.1/24

I have a wpf form with just a button for now, here's the code:我现在有一个只有一个按钮的 wpf 表单,这是代码:

MainWindow.xaml.cs:主窗口.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();
    }
}

} }

Output:输出:

I am Here!我在这里!

The thread 0x4378 has exited with code 0 (0x0).线程 0x4378 已退出,代码为 0 (0x0)。 System.Collections.ObjectModel.Collection`1[System.Management.Automation.PSObject] System.Collections.ObjectModel.Collection`1[System.Management.Automation.PSObject]

This will help.这会有所帮助。 foreach(PSObject obj in results) { Debug.WriteLine(obj.ToString()); foreach(PSObject obj in results) { Debug.WriteLine(obj.ToString()); } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM