Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

How to place PowerShell exception into a Win Form Text Box?

$
0
0

Greetings,

could you help me with a question?

Basically, I wrote a Win Form in Visual Studio 2010. My application opens powershell and runs a simple script. New-AdUser.....and it gives me an exception in powershell. I am trying to place this exception into a Rich TextBox in my Win Form.

Is there a specific command I could use to place PowerShell output into a rich text box.

So far I am doing the following:

 Process d = new Process();
            d.StartInfo.UseShellExecute = false;
            d.StartInfo.RedirectStandardError = true;
            d.StartInfo = new ProcessStartInfo("powershell.exe", module + "; " + command);
            d.OutputDataReceived += d_OutputDataReceived;
            d.Start();
            
           }

        private void d_OutputDataReceived(object sender, DataReceivedEventArgs e)
        {
            richTextBox1.Text = e.Data;
        }         The text box doesn't show anything

Viewing all articles
Browse latest Browse all 2562

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>