PS2EXE-GUI: "Convert" PowerShell Scripts to EXE Files with GUI

Overworking of the great script of Ingo Karstein with GUI support. The GUI output and input is activated with one switch, real windows executables are generated. With Powershell 5.x support and graphical front end. Now here:
4.7 Star
37,204 times
Add to favorites
E-mail Twitter Digg Facebook
  • all in one exe
    5 Posts | Last post July 22, 2017
    • Hello Markus, 
      You did a really good job ! thanks.
      I would like to know, if it's possible to include external files ( and folders ) into the .exe 
      In fact i have this structure : 
      - MyScript.ps1 ( with arguments )
      - MainWindow.xaml ( Powershell WPF )
      - resources ( folder containing pictures & dll assembly for my theme ).
      When i use PS2EXE-GUI, my Ps1 is compiled to .exe. all going fine !
      But all my external files have to be there beside my .exe
      My client want to have just all in one exe.
      Can you please bring me your help ?
      Thanks !
    • Hello Steven,
      I thought about your question but I see no way to help you. PS2EXE compiles a powershell script to an executable, no more and no less.
      If you want to have your resources integrated they need to be integrated in the powershell script already. I guess this is possible for XAML, maybe for one or the other graphic resource but not for assemblies.
      Sorry 'bout that.
    • Hello Markus, 
      I found a way to include all my external files into an .exe
      In fact, this exe is a Winrar contener which use SFX setup.
      But i've no idea how to call my arguments :(
      you'll find this tool here.
      Maybe a day it can help you :).
      If i find more, i will give you a feedback
    • Why not use the default windows Self Extracting Directive (SED)
      The wizrad/program : %windir%\system32\iexpress.exe
      This wizard allows you to add files and execution parameters.
      Supply as execution/installer sometinhg like: 
      powershell.exe -executionpolicy bypass -file yourpowershellscript.ps1
    • Maybe even better if you precompile the powershell 2 exe using this tool and have iexpress run that compiled executable.
      That way all readable powershell isn't extracted to the client.
      Supply as execution/installer: yourcompiled.exe
  • Start-Transcript is not working with PS2EXE
    3 Posts | Last post July 11, 2017
      Start-Transcript is not working with PS2EXE.
      if run the below script logtest.ps1 no issues.
      if run logtest.exe, the  Start-Transcript is not working. 
      The $ value has been from 'ConsoleHost' to PS2EXE_Host during the PS2EXE process.
      How to fix the Start-Transcript issue ?
      type logtest.ps1
      $logfile= "C:\programData\templog\logtest.txt"
      write-host " " $ "`r"
      write-host  "`r"
      if($ -eq 'ConsoleHost') {
          $Date = Get-Date -f HHmmss_ddyyyy
          Start-Transcript -Path $logFile
          write-host "`r"
      write-host "Testing host"
      write-output "Testing output"
      if($ -eq 'ConsoleHost') {
          $Date = Get-Date -f HHmmss_ddyyyy
          Stop-Transcript | out-NUll
      C:\compile>call "callPS2EXE.bat" "logtest.ps1" "logtest.exe"
      PS2EXE-GUI v0.5.0.5 by Ingo Karstein, reworked and GUI support by Markus Scholtes
      You are using PowerShell 4.0 or above.
      Reading input file C:\compile\logtest.ps1
      Compiling file...
      Output file C:\compile\logtest.exe written
      Config file for EXE created.
      C:\compile>logtest  PS2EXE_Host
      Testing host
      Testing output
    • Hello Bala58,
      please see my answer to the question "Issues found" from xja888 below.
    • Thanks
  • EXE Doesn't Launch
    2 Posts | Last post July 05, 2017
    • After I compile my script, my EXE just doesn't launch.  I get a super brief hourglass, then nothing.
      I have tried compiling my ps1 with several different options, none of which will even produce an error message when I launch the EXE.  My script is full of GUI stuff, and runs flawlessly pre-conversion.
      Where do I start? :)
    • Hello SCOMGabe,
      Debugging can be very difficult when there is no error message.
      First try I would make is to remove all "Out-Null" or "[VOID]" from the lines where assemblies or modules are loaded or a GUI window starts showing (.Show() or .ShowDialog()).
      Second try would be to set manual checkpoints in the script, for example with inserting lines (and counting the number high to identify each checkpoint):
      Write-Output "Checkpoint 1"
      Hope this helps finding the error.
  • Issues found
    4 Posts | Last post June 24, 2017
    • I'm probabaly asking too much but it would be really nice if the following works.
      write-host press any key to continue doesn't work in console mode. The screen exists anyway.
      $MyInvocation.MyCommand.Definition doesn't work.
      start-transcript doesn't log any echo
      Loading assembly fails, e.g System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null
      but still cannot connect to the database.
      Good works.
    • Hello xja888,
      so many questions :-)
      1. write-host press any key to continue  works fine for me.
      But this is the wrong syntax, try the correct one:
      write-host "press any key to continue"
      2. I already described how to handle $MyInvocation.MyCommand.Definition in the Remarks section of this web page under "Script variables:".
      3. I have to check this. Might take some time.
      4. I need some days to check this, I do not always have a SQL Server environment to test.
    • Hello xja888,
      tested the loading of SQL Server SMO assembly in a compiled script: it worked fine for me (tested Powershell v4 and v2).
      What message do you get when you remove the expression "| Out-Null" at the end of assembly loading command?
    • Hello xja88,
      with your question for Start-Transcript you really gave me a very difficult task.
      Microsoft did not document the transcript function so I had to check by myself:
      Powershell 2: transcripts are implemented in the powershell host (powershell.exe)Powershell 3: transcripts are implemented in the powershell host (powershell.exe)
      Powershell 4: transcripts are implemented in the commandlets Start-Transcript, Out-Default and Stop-Transcript
      Powershell 5: transcripts are implemented in the commandlets Start-Transcript, Out-Default and Stop-Transcript
      Powershell 6 (Beta): in the source code transcripts are implemented in the powershell host (powershell.exe)
      Because of this situation I do not see a possibility to help you, the risk of getting incompatible is to high for me.
      If you are using Powershell 4 or 5 there is a workaround:
      Pipe ervery command you want to be logged to Out-Default (e.g, Get-ChildItem | Out-Default).
      Or insert the following command in the line before the expression powershell.AddCommand("out-string") in PS2EXE.PS1:
      I'm sorry I can't do more for you.
  • Problem with noconsole parameter
    8 Posts | Last post June 21, 2017
    • Hi
      I wanted to ask something about the noconsole parameter.
      I have this script
                  # Create Job to compile Net Use in background
      	     $jobCo = Start-Job -ScriptBlock {PARAM($drive,$path,$Log,$Pass); Net Use $drive 
                  $path $Pass /USER:$Log} -ArgumentList @($drive, $path, $Log, $Pass)
      		 # After 3sec continue the script even if job doesn't finish
      		 Wait-Job $jobCo -Timeout 3
      		 $validCo = 0
      		 $listNet = $network.EnumNetworkDrives()
        foreach($Net in $listNet){
      	             if($Net.Substring(0,2)-eq $drive){
      				 $validCo = 1
      				 Net Use $drive2 $path2 $Pass /USER:$Log
      		                 Remove-Job -State Completed -ErrorAction SilentlyContinue
      When I run it with -noconsole parameter it crashes and says that the file .exe has stopped functioning.
      Can anyone please help me with this ?
      Thanks in advance
    • Hello Abhishek Ravi,
      I compiled the code fragment you posted and it works fine with the parameter "-noconsole" (I do not start it in a form since this code part is missing). But I have a guess what's going wrong:
      net.exe is a console program and you start it without a console. You might try to start it with a console:
      cmd.exe /c net use $drive $path $Pass /USER:$Log
    • Hi Markus
      Thank you very much for your response. 
      I think I get the problem.
      I actually need to create an application that does not use console.
      Is there a substitute for net.exe or net use that does not use console such as NewPsDrive. 
      If yes, can you please tell me how to implement it in my code.
      This would be greatly appreciated as I am new to PowerShell.
      Thanks :)
    • Hello Abhishek Ravi,
      instead of
      Net Use $drive $path $Pass /USER:$Log
      I think the three following lines should work:
      $PASSWORD = ConvertTo-SecureString $Pass -AsPlainText -Force
      $CREDENTIAL = New-Object -Typename System.Management.Automation.PSCredential -Argumentlist $LOG, $PASSWORD
      New-PSDrive –Name $DRIVE[0] -PSProvider FileSystem -Root $path -Persist -Credential $CREDENTIAL
      But, I can not test this in my Environment, no warranty.
    • Thank you :)
      I will look into this.
    • Hi Markus
      Just one last thing.
      I tried both with PS-Drive and net use.
      With both, after execution and closing of the Form, a dialog box with the title "ExeFileName.exe" appears with a text "Cancel" and a button "OK".
      Is is possible to remove this dialog box altogether and close the form and complete the execution without any such hassles. (Maybe by modifying the ps2exe.ps1 code). 
      This only happens with the noConsole option by the way.
      I request you to kindly help me with this as I have been trying to solve this by myself since Saturday.
      Thanks in Advance :)
    • Hello Abhishek Ravi,
      I have a guess what the reason is:
      You start the windows form window somewhere in your script with a command like this:
      You have to change it to
      as the command returns the text "Cancel" which is displayed in a message box. [VOID] "eats" everything returned.
    • Hi Markus
      I can't thank you enough for this.
      Worked like a Charm :)
      Best Regards
  • Start-Process without output
    3 Posts | Last post June 12, 2017
    • Hi,
      I have one question concerning the -noconsole parameter:
      i have a script, that calls an exe with the Start-process commandlet.
      Start-Process -Filepath wpeutil.exe -argumentlist "initializenetwork" -WindowsStyle Hidden -passthru -wait
      When i convert that ps1 to an exe with the -noconsole Parameter, always a GUI pops up because of that Start-process Commandlet and show an output of the process with a OK button, which i dont need in that case.
      Is it possible to surpress that GUI or to do a -noconsole without a GUI (as it was in the original script)?
      Thanks in advance and greetings
    • Hello Sebow,
      the answer depends on what you are trying to do, I have two ideas:
      1. Omit the paramater "-passthru". This parameter generates output you might not need.
      2. Append Out-Null to the pipeline:
       Start-Process -Filepath wpeutil.exe -argumentlist "initializenetwork" -WindowsStyle Hidden -passthru -wait | Out-Null
      Maybe the parameter -RedirectStandardOutput of Start-Process will help you.
    • Hello Markus,
      Thanks for the fast answer - you were right, it was the "-passthru" paramter, it's working now, thanks!
  • Wrong output type for compiled script
    9 Posts | Last post May 27, 2017
    • Hi, I have a script which runs the msdl library compiled for windows. When I'm downloading a file by running the .ps1 file, the output shows download percentage and updates as it progresses.
      However when I run the exe compiled from the .ps1 script, the output is in red, prefaced with "ERROR: ", and keeps printing and scrolling the screen, rather than updating the same line.
      Is it possible to manipulate the output type of the script or the specific command so it appears as intended?
    • Hello Krumpet,
      I cannot reconstruct this behaviour. I had the idea that the powershell command Invoke-WebRequest is executed in your script. As PS2EXE does not support Write-Progress in console mode, there is no percentage display, but no error message either.
      Do you think you are able to post the powershell command(s) that is responsible for the percentage or error output?
    • Hi Markus, thanks for the swift reply. I've uploaded some screenshots of the code and outputs here:
      The actual command that downloads/outputs is msdl (here
       (documentation here: which I've compiled for windows as it is unix-based originally. I hope this sheds some light, as I'm not too familiar with either the inner workings of MSDL or with powershell output types. Please let me know if there's any other info I can provide that would be relevant.
    • I've traced the output itself to the file network.c, where output done using their own display function, where the specific output I'm getting is sent to STDERR. Is it possible from the powershell script calling the .exe file to redirect its error output back to stdout? Rather than to edit the C code of the program I want to run.
    • Apologies for commenting multiple times, as there's no edit option.
      Simply redirecting stderr to stdout solved the ERROR message and red text color, however the text is still written consecutively rather than as an updating progress display. Is there a way to amend this? Since it does work as intended in the script version.
    • Hello Krumpet,
      you found out that you can redirect output in powershell or cmd batch by appending "2>&1".
      I have no idea how to suppress the carriage returns since msdl.exe is responsible for the output. The same behaviour occurs with the "not compiled script" when you redirect the error to the standard Output.
    • Hi Markus,
      Thank you for the help. I see now what the reason was for receiving output formatted as if it were an error. However, I still don't understand the difference in behavior when the output is not redirected from stderr to stdout - in the 'not compiled script' the text displayed as it was intended to, whereas post-compilation the behavior was different. Is there a way to change the way standard error output is handled in the PS script, such that the compiled result would be more like the intended one?
    • Hello Krumpet,
      I looked for the behaviour in the source code of msdl and ps2exe.
      The reason for this is that at the end of each line of output a newline character is appended by ps2exe. I could not work out how to prevent this, maybe it is not possible.
    • Hi Markus,
      Thank you for going in so deep to try and fix this problem. I was able to replicate the output as it was in script form/in linux, by piping the output to a ForEach loop and based on the line either going to a new line or overwriting the current one. For future reference (in case anyone encounters this specific issue or if I lose the script :P ):
      cmd /c .\msdl.exe -s2 $address -o $filename '2>&1' | ForEach-Object {
              if ($_.startswith("DL")) {
                  Write-Host -NoNewline "`r$_" ### THIS is the part that overwrites the last line printed
              else {
                  if ((-not $first) -and (-not $newline)) {
                      Write-Output "" # for newline between files
                  Write-Output "$_"
  • I am getting error while executing the .exe of powershell script
    2 Posts | Last post May 26, 2017
      No error in compile, but getting following error while running the .exe file.
      Error : This Script must be saved as a .ps1 file
      P:\PowerShell\PS2GUI>call "callPS2EXE.bat" "list_all_DB2Clients.ps1" "list_all_DB2Clients.exe"
      PS2EXE-GUI v0.5.0.5 by Ingo Karstein, reworked and GUI support by Markus Scholtes
      You are using PowerShell 4.0 or above.
      Reading input file P:\PowerShell\PS2GUI\list_all_DB2Clients.ps1
      Compiling file...
      Output file P:\PowerShell\PS2GUI\list_all_DB2Clients.exe written
      Config file for EXE created.
    • Hello Bala58,
      I'm sorry but I have not enough information to find the reason for this error. Maybe the script tries to restart itself elevated or in STA mode. This can only succeed in a ps1 script.
      Please search for the text "This Script must be saved as a .ps1 file" in the original script and try to find out what the script is trying to do before the error is given out.
  • ProductName and Version
    6 Posts | Last post May 25, 2017
    • Again me:)
      Is it possible to provide a productname and version to the exe? When pinning to startmenu the Name is missing because it is not in the exe. 
      The version would be important to know.
    • Hello Michael,
      I tried to pin a generated exe to the start menu: I see no problem, the name of the exe file is used in start menu.
      You can make a test whether it would help you if you do the following:
      1. Make a copy of ps2exe.ps1
      2. Open the copy of ps2exe.ps1 with your favorite text editor and search for the expression "namespace ik.PowerShell"
      3. Insert following lines in the line before the found expression:
      using System.Reflection;
      [assembly:AssemblyDescription("This is the description")]
      [assembly:AssemblyProduct("Test Application")]
      [assembly:AssemblyCopyright("Copyright © Markus Scholtes 2016")]
      4. Change the strings to the values of your choice
      5. Compile your script with the copy of ps2exe.ps1
      The resultant exe now has your chosen name and version property (among the others).
      Would you please give me a feedback?
    • Hello,
      is it possible to set the Assembly Attributes by command line parameters?
      I tried to use String variables like
      and got an error message:
      Could not create the PowerShell .exe file because of compilation errors. Use -verbose parameter to see details.
      AUSFÜHRLICH: c:\Users\USERNAME\AppData\Local\Temp\ksdnbb42.0.cs(16,2) : error CS0116: Ein Namespace kann nicht direkt
      Member, wie z.B. Felder oder Methoden, enthalten.
      AUSFÜHRLICH: c:\Users\USERNAME\AppData\Local\Temp\ksdnbb42.0.cs(28,1) : error CS1671: Eine Namespacedeklaration darf
      keine Modifizierer oder Attribute aufweisen.
      It would be nice to use command line parameters instead of editing the Script file.
    • Hello ChrDa,
      I will implement command line parameters for assembly attributes in the next version of my script. But this might take some weeks.
      I guess the error you get has two reasons:
      1. You have to double quote the attribute value, e.g.:
      2. The attribute commands have to be placed BEFORE the expression
      "namespace ik.PowerShell"
      in ps2exe.ps1
    • Hello Markus,
      you are right, rhe problem are the missing double quotes, but the position war right. What a stupid mistake. It would be nice, when you put this feature into the script.
      Thank you very mutch.
    • Hello Markus,
      thanks for implementing. It works perfect.
  • How to pass Arguments/Switches to compiled version (EXE).
    2 Posts | Last post May 17, 2017
    • can you provide me an example on how to pass user defined arguments/switches to compiled version .EXE.
      demo.ps1 input.csv output.txt
      Can I do same for .exe
      demo.exe input.csv output.txt
    • Hello Surya Prakash,
      as you guessed right, just pass your arguments to the compiled executable as if you would pass them to your script.
161 - 170 of 184 Items