Hi Markus, first of all, my compliments for the wonderful job! I would like to know if there is a way to make the console output windows 132 characters wide. I need it to avoid the wrap-around of the output messages of my script.... Regards. Franco
Hello lastbutnotleast, I think I do not understand your question. The console output is not wrapped by PS2EXE and the size of the console window can be set by using $Host.UI.RawUI. WindowSize as in any powershell script. Can you explain your situation more detailed? Greetings Markus
Markus, thank you very much for your support. Your answer has been enlightening :-) I usually run scripts from ISE, so I never had to worry about the console window size. Now I understand how to solve my simple problem ;-) Greetings. Franco
Thanks Markus This is working fine with parameters now. Is there a way that I can increase the prompt textbox width to at least 100px? Regards Jia
Hello xja888, hope I got your question right: you want the textfield in the inputbox to be always at least 100px wide? To accomplish this you have to do the following change to ps2exe.ps1: Open ps2exe.ps1 with your favourite text editor and change line 938 from textBox.SetBounds(12, label.Bottom, label.Right - 12, 20); to textBox.SetBoun ds(12, label.Bottom, Math.Max(label. Right - 12, 100), 20); (you might search for the expression "textBox.SetBou nds" to find the correct line) Greetings Markus
Hi Markus, First of all, thank you for all your job. I'm very happy to use it ! However I have a little issue with the -NoConsole parameter : As soon as I add the -NoConsole parameter, there's a popup window which appears when I close the form (with "myFileName.exe" as window title and "Cancel" text as value). How can I rid off that unwanted last window please ? Thank you very much, Anthony
Hello Anthony 974, I have a guess what the reason for this behaviour is: You start the windows form window somewhere in your script with a command similiar to this (the name of the variable $Form may vary): $Form.Showdialog() You have to change it to [VOID]$Form.Sho wdialog() as the command returns the text "Cancel" which is then displayed in a message box. [VOID] "eats" everything returned, so "Cancel" is not displayed anymore. Greetings Markus
It works ! Thank you very much for the tips and the explanation. I'd like to point your reactivity to answer questions which in my opinion is very fast. Best regards, Anthony
I mostly build powerhell GUI (form type) of scripts and wondering if there could be or there is an option where I can compile as hide console by default but with some /switch or built in command make it show on the fly
Hello Hunwarrior, when you compile a script with the parameter -NoConsole, then no console is started when then compiled exe runs. But remember, with the parameter -NoConsole every output is redirected to windows forms (like messageboxes or inputboxes). If you want no output, you have to use the switch -NoConsole and take care that your script has no output (maybe by redirecting output to $NULL). Greetings Markus
Well the point is that I didn't wrote proper feedback system so whenever there is error with my commands bachind I can't see the error message, that's why I would like to to open console optionally.
Hello Hunwarrior, I have no idea how to do what you want to do because the Console / NoConsole decision is a parameter for the compiler. You have to choose if there is a console at compile time and not at run time. Maybe you can compile with console and hide it at startup. In case of error you can unhide the console. Greetings Markus
Hi Markus, I was thinking about something similar but as you did this compiler I thought you might be able to build in option to compile in a way you said so if I ran the exe with -console then it will bring up the console. Greetings Hun
Sorry in advance if I haven't found answer to this question - I searched though. The issue is that when I run my script as .ps1 - all modules, GUI and functionality behaves as intended, though if I compile it to .exe - modules seems not to be working. All the functionality, except parts where scripts needs to work with PSRemoteRegistry and Quest AD snippet, works. Is there something in exe config file I am missing? Or something in compilation script I need to amend/alter?
Hello Mykolas J, modules should work fine. Please try the following: - check if your modules are loaded in your script (e.g. with Add-Type) - remove the redirection of errors from the loading commands - remember that no profile scripts are executed in compiled executables - are you getting errors when executing the commands from PSRemoteRegistry and Quest AD? Greetings Markus
Thanks for continuing this script! I am completely scratching my head, I have a script which does an add-adgroupmember. The script works fine interactively however after the conversion the script is throwing an error. A positional parameter cannot be found that accepts argument 'xxx' Unable to remove xxx, A positional parameter cannot be found that accepts argument 'xxx'.[0] Code: Add-ADGroupMemb er -identity $adminGrpVal.di stinguishedName –Members $tmpSAM.disting uishedName -Confirm:$false I have tried various iterations of the syntax, using SamAccountNames , removing positional parameters, etc but EXE still throws the error. Any help would be appreciated
Hello Flor H, sorry for the late answer, I have been on vacation in Italy. The minus sign in "-Members" is not a minus sign, but a character with ASCII code 0x96. Please try to replace it with the correct character. Greetings Markus
Well don't really understand. I optimized some process and lines in code and don't replay the error too... Maybe a bug in my code... Thanks and sorry for the inconvenience.
Try this: Add-ADGroupMember -identity $adminGrpVal.di stinguishedName -Members $tmpSAM.disting uishedName -Confirm:$false (copy and paste) This is wrong: Add-ADGroupMemb er -identity $adminGrpVal.di stinguishedName <b>–</b>Members $tmpSAM.disting uishedName -Confirm:$false
HI thanks for the help and suggestions, SagiK the code as written is correct, I think when cutting and pasting into the web it added the <b>-<b> Markus thanks for the reply, I also was on vacation but not in Italy ;-) How do I replace the '-' within the code? I have been looking for examples on how to write the command but I haven't found anything. Interesting enough when I run the code interactively it works just fine, and when I use Powergui's 'compile script' feature it works. There are other commands in the code which contain the hyphen that are working, its seems to be only the Add-AdGroupMember which is giving me grief. Again any help would be greatly appreciated
Hello Flor H, I' sorry, when the wrong "-" is not the reason for the error, I have no idea what's wrong. I tried your code by myself: When I copy your code, I get the error (because of the wrong -). When I retype the command, everything is working fine. Greetings Markus
Dear Markus, Thank you for this cool tool. I have created a script which contains forms, and put the company logo ("logo.ico") to this form. $Form.Icon = New-Object system.drawing.icon("logo.ico" ) When this file is not located in the folder, I got error message. Is it possible to add this resource to the .exe file when compiles? Regards, Krisztian
Hello SagiK, there is no possibility to embed the icon with PS2EXE. You have to embed it to the powershell source file. To do this you might do the following: 1. Create a base64 string out of your icon: [CONVERT]::ToBase64String((Get -Content "logo.ico" -Encoding BYTE)) Copy the resulting string to the clipboard 2. Insert the following lines to your script: Add-Type -AssemblyName PresentationFra mework $Base64Text = 'REPLACE_WITH_B ASE64TEXT' $BITMAP = New-Object System.Windows. Media.Imaging.B itmapImage $BITMAP.BeginIn it() $BITMAP.StreamS ource = [System.IO.Memo ryStream][Syste m.Convert]::Fro mBase64String($ Base64Text) $BITMAP.EndInit () $BITMAP.Freeze( ) # Convert the bitmap into an icon $IMAGE = [System.Drawing .Bitmap][System .Drawing.Image] ::FromStream($B ITMAP.StreamSou rce) $Form.Icon = [System.Drawing .Icon]::FromHan dle($IMAGE.GetH icon()) 3. Replace REPLACE_WITH_BA SE64TEXT with the copied base64 string This should work as powershell script and as compiled executable with PS2EXE. Reference: https://blog.ne tnerds.net/2015 /10/use-base64- for-notifyicon- in-powershell/ Greetings Markus
c3rbc3rb Hi In first sorry for my english :) I try to protect my code by using your program but i have some issus when i try to use it with Windows Task Scheduler and arguments I try to launch C:\TEMP\Program.exe -arg1 test -arg2 test2 / the program start but stop immediatly C:\Windows\Syst em32\WindowsPow erShell\v1.0\po wershell.exe -File C:\TEMP\Program .exe -arg1 test -arg2 test2 / works Without Windows Task Scheduler the EXE work Can u help me ? Thanks
New test : if i lunch Windows Task with .EXE without "-noconsole" it's works...
Hello c3rbc3rb, I tried to replay the error you mentioned, but I'm sorry I can't. A compiled test script is processing all parameters fine when started as a scheduled task independent of being compiled with or without the option"-noConsole". Can you give me more information about your program and what parameters it expects? Greetings Markus
PowerGUI from Quest allows you do add files to the exe so that when the exe runs, it expands into a temp directory and all files are there for the ps1 to see. Any chance this tool does that and if not, can it be added? MSI files are a prime example of a file a ps1 may need to open.
Hello jbruns2010, sorry for the late answer, I have been on vacation (and sad that I'm back :-)) A self-extracting feature in ps2exe is not easy to realize. You have to write the compress method in powershell and have to write the decompress and starting routines in C#. It is possible to do, but means much work. I do not plan to code an implementation. Please read the question "all in one exe" below to find hints for using an external tool to create an compressed self-extracting exe file. Greetings Markus
Hi Markus, I have a very simple script, with just a one line on it: Write-Host "Hello World" After converting it into a .exe I get NO OUTPUT if I try to run it using a Powershell ISE shell but, it runs fine from a regular DOS prompt.
Hello FabRod, I guess there is an output, but the shell closes immediately after the Output has been done. Try to add the additional command "Read-Host" in the line after the Write-Host command. This waits for the return key. Greetings Markus
Hello FabRod, I read your question once more and discovered that I answered wrong. There are several limitations in ISE as it is not a full implementation of powershell, you may look here: https://blogs.msdn.microsoft.c om/powershell/2 009/02/04/conso le-application- non-support-in- the-ise/ or here: https://blogs.m sdn.microsoft.c om/powershell/2 009/04/17/diffe rences-between- the-ise-and-pow ershell-console / You have to use Start-Process CompiledScript. exe to run your compiled script CompiledScript. exe Greetings Markus