locked
Creating GUI for PowerShell script with Visual Studio 2012 RRS feed

  • General discussion

  • Hello all,

    Has anyone created a GUI for a powershell script with VS2012 on C#?

    I`ll be glad to see some nice ideas about that!

    Tuesday, October 16, 2012 7:42 AM

All replies

  • Hi,

    Take a look: http://technet.microsoft.com/en-us/library/ff730941.aspx, You can use this to create a GUI :)


    -- Kamil Tatar

    Tuesday, October 16, 2012 7:55 AM
  • With Windows Forms it is (nearly) impossible because you have to translate the different syntaxes! (even embed as c# Object Code makes no sense!)
    With WPF you can create your GUI with Visual Studio, Copy the XAML and paste it to PowerShell:

    # make shure that the script is running in single thread apartmend (STA) Mode 
    If ($host.Runspace.ApartmentState -ne 'STA') { 
    	Write-Host "Script is not running in STA mode. Switching "
    	$Script = $MyInvocation.MyCommand.Definition
    	Start-Process powershell.exe -ArgumentList "-sta $Script"
    	Exit
    }
    
    # Load the WPF Assemblys
    Add-type -AssemblyName PresentationCore
    Add-type -AssemblyName PresentationFramework
    
    # XAML Window code
    [xml]$XAML = @"  
    	<Window  
    		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    		Height="150" Width="150">  
    	</Window>
    "@  
       
     # 'compile' the XAML
     $Reader=(New-Object System.Xml.XmlNodeReader $xaml)  
     $Window=[Windows.Markup.XamlReader]::Load( $Reader )  
       
     # Show XAML GUI  
     $Window.ShowDialog() | out-null

      With Windows Forms you can use Sapien PrimalForms Community Edition. Which is free.

    You can get it at http://www.sapien.com/downloads. You need to register and is the download section, browse to "Community Tools" -> "32 bit" -> "PrimalFormsCE.exe".
    Even better still is Powershell Studio 2012 from Sapien Techologies.
     OR
    Admin Script Editor (ASE) from iTripoli there you need the Enterprise Edition
    http://www.adminscripteditor.com/


    Please click “Mark as Answer” if my post answers your question and click “Vote As Helpful” if my Post helps you.
    Bitte markiere hilfreiche Beiträge von mir als “Als Hilfreich bewerten” und Beiträge die deine Frage ganz oder teilweise beantwortet haben als “Als Antwort markieren”.
    My PowerShell Blog http://www.admin-source.info
    [string](0..21|%{[char][int]([int]("{0:d}" -f 0x28)+('755964655967-86965747271757624-8796158066061').substring(($_*2),2))})-replace' '
    German ? Come to German PowerShell Forum!


    Tuesday, October 16, 2012 9:22 AM
  • If you like to have a compiled .NET GUI Aplication you can host Powershell inside you app:

    How To: Host the PowerShell Runtime
    http://blog.mitchdenny.com/2008/02/23/how-to-host-the-powershell-runtime/

    Hosting Windows PowerShell Part 1 and 2

    http://channel9.msdn.com/shows/The+DFO+Show/The-DFO-Show-Hosting-Windows-PowerShell-Part-1/
    http://channel9.msdn.com/Shows/The+DFO+Show/The-DFO-Show-Hosting-Windows-PowerShell-Part-2

    Writing a Windows PowerShell Host Application
    http://msdn.microsoft.com/en-us/library/windows/desktop/ee706563%28v=vs.85%29.aspx


    Please click “Mark as Answer” if my post answers your question and click “Vote As Helpful” if my Post helps you.
    Bitte markiere hilfreiche Beiträge von mir als “Als Hilfreich bewerten” und Beiträge die deine Frage ganz oder teilweise beantwortet haben als “Als Antwort markieren”.
    My PowerShell Blog http://www.admin-source.info
    [string](0..21|%{[char][int]([int]("{0:d}" -f 0x28)+('755964655967-86965747271757624-8796158066061').substring(($_*2),2))})-replace' '
    German ? Come to German PowerShell Forum!

    Thursday, October 18, 2012 5:45 AM
  • Hi,

    Just checking in to see if the suggestions were helpful. Please let us know if you would like further assistance.

    TechNet Subscriber Support

    If you are TechNet Subscription user and have any feedback on our support quality, please send your feedback here.


    Yan Li

    TechNet Community Support

    Friday, October 19, 2012 2:30 AM