Creating an Application from a PowerShell Script - Converting PS1 to Exe

PowerShell is a very powerful tool, but explaining to end users how to utilize a script can be a complicated and frustrating process. One way to remove the education step is to turn your PowerShell script into an executable application. If you have followed our guide on creating a GUI for your script, converting the script into an executable application is the final step.

With our new script packaging PowerShell Module, you can run a few commands and soon your script will become an application. If you are experienced and comfortable with using PowerShell Modules, we have made it available for download here. However, if you are unfamiliar with the process, this post will guide you through using our PS2EXE-GUI application that removes the need for understanding PowerShell Modules.

We have made our PS2EXE-GUI application available for purchase on our App Store here. After you have purchased the application you will receive an email with your license key and a download link. The following steps will guide you through installing and utilizing the application to get your own scripts converted into an application.

First, run the installer file that you have downloaded and when prompted, enter your license key and the email address you used to purchase the key.



Once you have successfully activated the product, launch PS2EXE-GUI and you will see the screen below.


The areas highlighted in red indicate a required field. To begin converting your script into an application, click "Browse" in the Script row and select your script file.

Next, click "Browse" on the exe row and choose where you want to save your application exe file and enter the name you would like it to have. This will be the name and file you will see when launching your newly created application.

Once you have selected a name, enter it into the "Title" field. The Title field is what will be filled into the exe details if you right click the application after it is created.

From this point, all of the other fields are optional or will be filled in automatically when you click "Build."

Here are some additional details for the fields in the "File Info" section that will impact how your application runs.

Architecture - This options allows you to choose what platform the exe will run on, You can choose between x86, x64, or any cpu platform.

Icon - This will choose the icon file of the exe, and if you use the method we described in our post about building a GUI, the icon will also show in the task bar and menu bar of your application. If your Anti-Virus (AV) is flagging the application exe as a virus, try a different icon file or try to convert the file as these could be the cause.

Note: If you are storing the icon as code within your script, some AV applications will see the code as being malicious.

Require Admin Rights - Checking this box will put a require admin flag on the exe. If this is enabled, users running the application will be prompted to enter admin credentials, or accept the security prompt if they are an administrator.

No Console - Checking this box will make it so the exe doesn't open a Command Prompt window. Without this box checked the exe will open a Command Prompt window. When you use this option, any output from a command in your script will show in a message box. For example, if you have "Write-Host 'Complete'" in your script you will see a message box showing "Complete."

Once you have set all of the options for your script click "Build" and when the process is complete you will see "Success" message and can find your app in the path specified.

ADVANCED NOTES: If your script has parameters, you will still be able to use them.
ex: <YourEXEFile>.exe -YourParameter

If you use the variable $PSScriptRoot, it will no longer work in the compiled exe. In place of this, you will want to add these lines to your script and replace any instance of $PSScriptRoot with $ScriptPath
if ($MyInvocation.MyCommand.CommandType -eq "ExternalScript"){ $ScriptPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition }else{ $ScriptPath = Split-Path -Parent -Path ([Environment]::GetCommandLineArgs()[0]) }

If you have any questions, feel free to post them in the comments section or email us at contact@mosaicmk.com and we will get back to you as soon as possible.

Comments