locked
How to run a PowerShell script from a Windows Form in Visual Studio 2010 RRS feed

  • Question

  • Greetings, I'm fairly new to Visual Studio and could use some assistance.  I'm creating a windows form to run a few existing PowerShell scripts.  I don't have PowerGUI or other VS/PowerShell integration tools and was just wondering if anyone has an example of how to call a powershell script from the form without any add ons.  Thanks in advance!

    Monday, October 8, 2012 6:48 PM

Answers

  • You probably want to do something like this:  http://msdn.microsoft.com/en-us/library/windows/desktop/ee706563(v=vs.85).aspx

    Alternatively you could try opening a powershell prompt and sending the script name to it, it may be a bit 'clunkier', but it would likely be easier than being a full-fledged host. For that you would just use the Process class to launch the powershell executable, and perhaps the stdin pipe to feed it the script commands, or pass the script to run as a launch argument the powershell environment (if it takes such arguments).

    Ryan

    • Marked as answer by Ego Jiang Monday, October 22, 2012 9:59 AM
    Monday, October 8, 2012 10:22 PM

All replies

  • You probably want to do something like this:  http://msdn.microsoft.com/en-us/library/windows/desktop/ee706563(v=vs.85).aspx

    Alternatively you could try opening a powershell prompt and sending the script name to it, it may be a bit 'clunkier', but it would likely be easier than being a full-fledged host. For that you would just use the Process class to launch the powershell executable, and perhaps the stdin pipe to feed it the script commands, or pass the script to run as a launch argument the powershell environment (if it takes such arguments).

    Ryan

    • Marked as answer by Ego Jiang Monday, October 22, 2012 9:59 AM
    Monday, October 8, 2012 10:22 PM
  • Hi Biged571,

    I marked Ryan's reply as answer.

    Please unmark it, if it is not the answer.

    Thank you for your understanding and support.
     
    Best regards,

    Ego [MSFT]
    MSDN Community Support | Feedback to us

    Monday, October 22, 2012 10:01 AM