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.

PS2EXE-GUI.zip
 
 
 
 
 
4.7 Star
(35)
33,470 times
Add to favorites
7/1/2019
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Exception Calling
    2 Posts | Last post July 12, 2018
    • When I run the exe file I get the error message ""SetBufferContents" with "2" argument(s): "Not enough storage is available to process this command"
      
      Any assistance would be greatly appreciated.
    • Hello DrHeinz,
      
      I need more information to answer to this. The function "SetBufferContents" is used for console screen manipulations, first of all for Clear-Host (or cls).
      
      Do you use Clear-Host in your script? If yes, try to comment the command out. Does the error still occur then? Do you change the size of your console in your script, or the codepage?
      
      Greetings
      
      Markus
      
  • Pop up box not showing out put
    2 Posts | Last post June 29, 2018
    • I am having some issues with longer outputs parsing Format-List | Out-String as a single line when running -NoConsole. In Powershell CanonicalName will display as a single line. With No Console, it wraps the data. 
      
      PS Command:
      Get-ADUser -Filter {samAccountName -eq $X} -properties * | select DisplayName,samAccountName,Enabled,CanonicalName | Format-List | Out-String
    • Hello jdangelo,
      
      since I use the standard WinForms output method "MessageBox.show()" to display output in -noConsole mode, there is no way to configure the formatting of the text but to insert Carriage Returns into the output text.
      
      Greetings
      
      Markus
      
  • Executing PS2EXE.ps1 inside an compiled OtherPS1.exe file problem.
    5 Posts | Last post June 24, 2018
    • Hi Markus.
      
      Example: $Args is an Array of parameters @("-noConfigfile", "-noConsole", "-requireAdmin")
      
      When I use splatting $Args, it's working only when executes Otherps1.PS1
      
      & $ps2exe $inputFile $outputFile @Args
      
      But it will fail when executes the compiled version Otherps1.EXE
      
      Output:
      ...
      You are using PowerShell 4.0 or above.
      Icon file D:\Powershell Scripts\True not found!
      
      I don't know this problem is normal when executes *.EXE file or this's a bug.
      I'm just a newbie to Powershell so if this problem is normal please excuse me :D
      
      Greetings
      MC
    • Hello Minh Cường,
      
      you cannot splat parameters to compiled scripts since they are real executables. Only commandlets can read the parameters in the collection.
      
      Greetings
      
      Markus
    • Hello Markus.
      
      In the compiled OtherPS1.exe I try:
      Write-Host $Args
      
      And the output is:
      -noConfigFile True -noConsole True -requireAdmin True
      
      Is that normal, Markus?
      
      Greetings
      
      Minh Cường
      
    • Hello Minh Cường,
      
      since there is an implicit conversion from [SWITCH] to [STRING] when splatting to an compiled script I think I cannot do anything about your error.
      
      The original PS2EXE script of Ingo Karstein did better in this situation, but had many misinterpretations of Parameters in other constellations.
      
      So I'm sorry to say that I do not guarantee proper work of splatting parameters to compiled PS2EXE scripts.
      
      Greetings
      
      Markus
    • It's not a problem, Markus :D
      
      I just want to know more about splatting parameters of your script.
      
      I will try something myself.
      
      Thanks you for your script, Markus.
      
      Greetings
      
      Minh Cường
  • Write-Progress
    2 Posts | Last post June 19, 2018
    • Any chance there will be support for Write-progress in console mode?
    • Hello TommyTrut,
      
      a proper implementation of Write-Progress in console mode would be very much work (every output would have to be hooked) for small benefit. So I do not plan to implement it.
      
      Greetings
      
      Markus
  • Script using Get-ADPrincipalGroupMembership
    8 Posts | Last post June 16, 2018
    • Hello Markus,
      I am using "Get-ADPrincipalGroupMembership" in my script. When I am running PS1 file(PowerShell script), it is giving the desired output. But, after creating exe file, the "Get-ADPrincipalGroupMembership" is not working.
      
      Please advise.
      
      Sample code:
      $s=Get-ADPrincipalGroupMembership $account_name |Select-Object -ExpandProperty saMAccountName | Where-Object {$_ -match "OOB-Management"}
      $s
    • I had the same issue.  I was able to add a line in the original script to load the module for active directory.  (Be sure to put in the actual file path not just the module name.)  After adding that line I was able to see the module actually load when the .exe is executed.
    • Hello JuanealB,
      Can you share the sample on how to add the module? Also, it will be more helpful if you provide me the actual location where I need to add the codes.
    • Hello Ashutosh Tripathi 14,
      
      as JuanealB stated right there is no autoloading of modules in compiled PS2EXE scripts.
      
      You have to load the Active Directory module manually with the command:
      Import-Module ActiveDirectory
      
      Greetings
      
      Markus 
      
    • Hello Markus,
      I am already using the "Import-Module ActiveDirectory" in my script and it is working fine when I am running the PS1 script. But, when I am generating the exe from PS1, it is not working.
      
      Thanks,
      Ashutosh
    • Hello Ashutosh Tripathi 14,
      
      your problem seems to be a bit more complicated.
      
      But to help I need to know what happens. You say "it's not working". What does this mean? Is there an error? Do you get unexpected results? Does nothing happen? Do other commandlets from the ActiveDirectory work?
      
      Greetings
      
      Markus
    • Hello Markus,
      
      Sample code:
      $sam="ashutosh.tripathi"
      $s=Get-ADPrincipalGroupMembership $sam |Select-Object -ExpandProperty saMAccountName | Where-Object {$_ -match "OOB-Management"}
      $s
      Read-Host "Please wait"
      
      When I am running this code in powershell/ps1 script I am getting correct output i.e.,"OOB-Management". But, when I am running the code after creating exe, I am not getting any output. I also tried to check with the different group names, but getting same result. 
      
      One interesting thing I found during my testing that if I replace OOB-Management with "Domain Users" group, then I am getting correct out in PS1 script as well as in exe file.
      
      Thanks,
      Ashutosh
    • Hello Ashutosh,
      
      before we dive too deep in to your script. You say it works with "Domain Users". Can this be an issue with special characters and the encoding of the source file?
      
      If special characters are used the source file has to be encoded as UTF8, 16 Bit-UNICODE works too. Encoding as ASCII or OEM can lead to side effects like those you are experiencing.
      
      Greetings
      
      Markus
  • Strange GUI
    3 Posts | Last post June 15, 2018
    • Hi Markus
      
      I have written a script that will be used on alot of servers and everytime someone logs on it should run. Now to do that I need an .exe file. When I used your script to convert my script into a .exe file, it has 7 popup windows where the first one has "0" and the second one has "1" all the way to 6. Then an error pops up saying "It is not possible, to invoke a method for an expression, which is NULL" (translated from german, might not be 1-1 but tried my best translating it).
      Now after this error my script finally pops up. But when I close it, I again get a popup window saying "Cancel" or "OK". 
      Now what might be the problem is, that I programmed my own GUI in my powershell script, but I am not the expert of what this script does.
      Is there a way to block these popup messages or another workaround? I would be thankful for your help.
      
      Thanks in advance
      Crowlex
    • "Now what might be the problem is, that I programmed my own GUI in my powershell script, but I am not the expert of what **this script** does."
      
      For clarity, I mean your script here, otherwise it would be quite confusing
    • Hello Crowlex,
      
      the PS2EXE Parameter "-noConsole" does not mean that there is no output, the output will be presented in message boxes.
      
      When you want to get rid of the Output you have to find the commands in your script (maybe in executing the script in ps1 form) that generate output and suppress it.
      
      You can do this by piping to Out-Null, e.g.
      Get-Process | Out-Null
      
      The Cancel or OK at the end of the script is the result of your GUI window. Find the expression that calls .Show() or .ShowDialog() and suppress the output with the [VOID] type, e.g.
      
      [VOID]$Form.ShowDialog()
      
      Greetings
      
      Markus
      
  • Get-Credential Stays in Console
    6 Posts | Last post June 14, 2018
    • Markus,
      
      Great work and thank you so much for creating this! I have an issue where Get-Credential only shows up in the console window after being converted. VB popups still work, but I cannot seem to get the proper credential window to appear.
      
      Please advise.
      
      Charlize
    • Hello Charlize V,
      
      do I understand your question right: you are compiling a script without using the Parameter -noconsole and wonder why there is no graphical dialog when calling Get-Credential?
      
      This was a decision Ingo Karstein made when initially creating the script. I think it was a good decision but I will check how to change this behaviour. This might take some time, hope that's okay for you.
      
      Greetings
      
      Markus
    • Hello Charlize V,
      
      the new version v0.5.0.11 of PS2EXE has the new parameter -credentialGUI. When set in console executables a graphical GUI is used for Get-Credential instead of console input.
      
      Greetings
      
      Markus
    • Markus,
      
      Thank you so much, but I cannot seem to get it to work. Yes, I am creating a console application without a GUI. Here's my command line for running ps2exe.ps1:
      
      Powershell -nop -ep ByPass "C:\Folder\ps2exe.ps1 'C:\Folder\Script.ps1' 'C:\Folder\Script.exe' -iconFile 'C:\Folder\Icon.ico' -title 'Script' -description 'Script' -product 'Script' -company 'Company' -version '1.0.0.0' -credentalGUI -runtime40"
      
      It still comes up in the console window itself as:
      
      Windows Powershell credential request
      Enter your credentials
      User name:
      
      And not the typical graphical prompt that allows the user to know that its a sercure prompt. Perhaps it's one of the other options I'm choosing? I tired it without -runtime40 and the same results.
      
      Many thanks,
      
      Charlize
    • Hello Charlze V,
      
      there is a typo in the "updates" section of this web page:
      The parameter is -credentialGUI, not -credentalGUI.
      
      Sorry for that, I will correct the description soon
      
      Greetings
      
      Markus
    • Markus,
      
      You rock! Works like a charm. Thank you so very much! Just in time to get this project out.
      
      Keep being awesome!
      
      Charlize
  • Error when calling ps2exe.ps1 inside other.ps1 file!
    6 Posts | Last post June 11, 2018
    • Hi Markus!
      
      I try to call ps2exe.ps1 in other.ps1 file by using & operator:
      & $ps2exe $inputFile $outputFile
      & $ps2exe $inputFile $outputFile -noConsole:$Null
      And some other calling method.
      I always see the compiling success (Output file $outputFile written) ouput in console follow the error below:
      
      The property 'Location' cannot be found on this object. Verify that the property exists.
      At D:\Powershell scripts\PS2EXE-GUI\ps2exe.ps1:261 char:2
      +     $referenceAssembies += ([System.AppDomain]::CurrentDomain.GetAsse ...
      +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException
          + FullyQualifiedErrorId : PropertyNotFoundStrict
      
      Only calling $ps2exe with -noConsole parameter is not generates the error:
      & $ps2exe $inputFile $outputFile -noConsole
      
      Can I manual fix this?
      
      Thanks very much for your great script.
    • How to fix this error?
      
      Sorry, my english is not good.
    • Hello Minh Cường,
      
      what program do you use to run the script?
      
      There is a bug in PS2EXE that leads to this error. This error should not lead to any further problem. I will fix it in the next version of PS2EXE.
      
      Greetings
      
      Markus
      
    • Hi Markus.
      
      I'm just calling PS2EXE.ps1 from a simple OTHER.ps1 wrapper on Powershell console, did not import to any program yet.
      
      On next version if you are adding a parameter option to not writing *.config file that will be great :D
      
      I don't like to modify your PS2EXE script so I made a .ps1 wrapper to customize some of my need.
      
      Greetings.
      MC
    • Hello Minh Cường,
      
      the new version v0.5.0.11 of PS2EXE released today has fixed the error "The property 'Location' cannot be found on this object".
      Additionally there is a new parameter -noConfigfile that suppresses generation of the config file (that is unnecessary in most cases).
      
      Greetings
      
      Markus
    • Thanks very much for your script, Markus :3
      
      Greetings
      MC
  • Write-Progress, color of progress bar
    3 Posts | Last post June 11, 2018
    • Hi
      
      When using write-progress in PowerShell script and converting til exe the progress bar indicator gets blue color insted of green as in PowerShell. How can i change this?
      
      Greetings,
      Nils
      
    • Hello Nilzy,
      
      I use the standard color for progress controls to display the progress bar. But you are right, there should be a choice to choose the colors.
      
      It will take some time, but I will implement this in the next version of PS2EXE.
      
      Greetings
      
      Markus
    • Hello Nilzy,
      
      the new version v0.5.0.11 of PS2EXE allows to set the progress bar color in -noConsole mode, e.g.:
      $Host.PrivateData.ErrorForegroundColor = "Green"
      
      But only if visual styles are not enabled.
      
      Greetings
      
      Markus
  • The Handle is Invalid
    12 Posts | Last post June 11, 2018
    • I've created an EXE that runs fine interactively.  However when trying to invoke the EXE from the scheduling app VisualCron, I get the error: "The Handle is Invalid".
      
      Anyone have any ideas on this?
    • Hello M Woffenden,
      
      you don't give me enough information to find the reason for this error. I guess there is a problem with the default streams (standard input, standard output, standard error). 
      Are you trying to change the user context of the process? Do you want to elevate the process on a remote system?
      
      Greetings
      
      Markus
    • Thanks for your reply.  You are right, there is an issue with the standard output.  In VisualCron there are two options: "store standard output" and "store standard error".  When I have either of these turned on, I get the"The Handle is Invalid" error.
      
      If I turn both options off, I can run the EXE version of my script.
      
      But I do want to store the output -- and this worked with the old version of PS2EXE.
      
      Any ideas on what might be happening here?  Any PS2EXE options that I should try?
    • Hello M Woffenden,
      
      did you compile with the Option -noConsole ? Then there is no console and of Course no console Output.
      
      Greetings
      
      Markus
    • Compilng with -noCompile allows us to run the EXE.  But does this option prevent writing to standard output?
    • Correction: Compiling with -noConsole allows us to run the EXE.  
      
      But does this option prevent writing to standard output?
    • Hello M Woffenden,
      
      yes, when compiled with the option -noConsole you generate a "real" Windows gui program which runs without a console. But standard output, standard input and standard error are only available in a console (obviously there is no place where an output could go if no console is present).
      
      So you have to decide: generate an executable without console and without standard output or an executable with console and standard output.
      
      Greetings
      
      Markus
    • Markus - becoming clearer.  
      
      I really do want a console app where I can write output.
      
      But this leads me back to my very first question.   When I create a console app and try to run it, I get the error: "The Handle is Invalid".  You said there is a problem with the default streams (standard input, standard output, standard error). 
      
      Any ideas on how I might debug this? 
    • Hello M Woffenden,
      
      now I am confused.
      
      When you compile without -noConsole, there should be a console and so standard output should work.
      
      When you compile with -noConsole, there is no console and there is no standard output so you might get the error "The handle is invalid".
      
      Is this your Situation?
      
      Greetings
      
      Markus
    • Hi Markus,
      
      I have the same problem.
      I used the generated EXE file from ps2exe in another powershell script.
      
      It seems that when I activate the error output redirection, the error message "The handle is invalid" shows up.
      
      To reproduce the error, I just created an executable from a PS1 which prints a text and I called it in another ps1 with the following code:
      $output = &'YOURPS1EXE' 2`>`&1
      
      You will normally get the error message.
    • Hello M Woffenden, hello Albert Rag,
      
      as you found out the input stream is not working correctly under some circumstances in compiled PS2EXE scripts. I will need some time for research on this.
      
      What I found too (that does not produce the error): I forgot to send error output to the error stream :-) . This will be fixed in the next version of PS2EXE.
      
      Greetings
      
      Markus
    • Hello M Woffenden, hello Albert Rag,
      
      the new version v0.5.0.11 released today fixes the errors with redirection
      
      Greetings
      
      Markus
71 - 80 of 143 Items