Hello, greetings and welcome. I’m Brien Posey. In this video, I’m going to show you one of my favorite utilities for PowerShell. It’s called PS2EXE. The idea is that you can take a PowerShell script and turn it into an executable application.
https://youtube.com/watch?v=o730kcgY2Bk%3Fsi%3DsNHb8qM8u8i0B9Qr
Posey provides step-by-step instructions on installing PS2EXE, demonstrates its practical use, and highlights key features and security considerations. Additionally, he explains how to access a PS2EXE GUI frontend that simplifies the process for those who prefer a visual interface
As you can see, I have the GitHub page open for PS2.EXE. Now, you don’t have to go to GitHub to download PS2EXE. You can install it directly from PowerShell. The way that you do that is by typing:
The main reason I wanted to show you this GitHub page is simply because if you scroll down, you can see the full syntax. Now admittedly, the full syntax is quite a bit to take in, but you don’t have to use all these parameters. PS2EXE is actually really easy to use.
Linking the script to the application’s shortcut is one way, but there’s a smoother solution – converting the PowerShell script into a standalone executable using PS2EXE.
PS2EXE transforms PowerShell scripts into standalone executables. This means the script works independently and looks professional.
In software packaging, it’s rare but useful to run specific commands before launching the main app, often by converting a PowerShell script to an EXE shortcut.
In this article, we’ll explore the process of converting PowerShell scripts to standalone EXEs using PS2EXE and seamlessly integrating them into software packages with Advanced Installer.
Converting PowerShell script to EXE
To start converting PowerShell script to EXE, get the PS2EXE tool. It’s available online in various versions.
Then open the GUI:

After refining your PowerShell script, run PS2EXE and input your PowerShell script. It will create the standalone EXE.

That was easy right?
Now if we open up the EXE file resulted, we can see that the PowerShell script works:

Using the EXE in your Package
Considering that the resulted EXE is your application’s shortcut, adding it into your package with Advanced Installer is straightforward.
1. Go to the Files and Folders page and drag the EXE.

2. Right-click the executable and select New Shortcut To > Installed File.
3. A new window will pop-up. Complete the prompted details, and you’re set.

And that is it, that is how easily you can convert a PowerShell script to an executable and use it in your package.
New to Advanced Installer? Streamline your software packaging with Advanced Installer’s 30-day free trial!
Conclusion
With tools like PS2EXE and Advanced Installer, you can achieve both effortlessly, showcasing the power of effective automation in modern software practices.
Adding Attributes to the Executable File
Now, there are a couple of other things that I want to show you about PS2EXE. To do that, I’m going to switch back over to my PowerShell window.
What I want to do is create an executable that is a little bit more fully featured. Let me switch back to my Command Prompt for just one second and open File Explorer. I right-click on the executable and go to Properties and the Details tab. You’ll notice that we don’t have a whole lot of details here. Let’s go ahead and change that.
I’ll go ahead and press Enter. The output file has been created.
So, let’s look at what we’ve done.
I’m going to switch back over to my Command Prompt window. I’ll type , and here you see mycalc2.exe, which we just created. You’ll notice that the file size is slightly larger than mycalc.exe even though we compiled the same PowerShell script. I’m going to type:
I’ll press Enter, and we can see that the calculator still runs. I’ll go ahead and close this out.
The attributes that I showed you are just a small sample of what you can do using PS2EXE.
As a matter of fact, I’ll switch back over to PowerShell and type:
I’ll press enter. You can see the full syntax and that there are a huge number of parameters that are supported. That kind of goes back to what I showed you at the very beginning of the video with the GitHub page.
Why You Shouldn’t Embed Passwords
One of the extremely important things to keep in mind whenever you compile a PowerShell script into an executable is that you shouldn’t embed a password in the PowerShell script, particularly if we’re talking about clear text. The reason for that is that you can reverse engineer an executable and extract the PowerShell code that was used to create it.
Let me show you how that works.
As you can see, I’ve got the Command Prompt open and I’m in my scripts folder. I’ll type , and you can see that we created an executable file a moment ago called mycalc.exe. What I’m going to do is type . Then I have to provide a file name. I’ll just call this CalcCode.ps1.
mycalc.exe -extract: CalcCode.ps1
I’ll press Enter. And if I type , you can see that I’ve got a brand-new PowerShell script called CalcCode.ps1 That wasn’t there a moment ago. Now I’ll type:
When I press enter, you can see the actual code that was used to create the executable. So, that’s why I said you shouldn’t embed a password in a PowerShell script if you’re going to be compiling it into an executable. There is a way to reverse engineer that script, access the PowerShell code, and retrieve that clear-text password from the code.
How PS2EXE Works
Let’s look at how this works.
I’m going to go ahead and close out my browser, and here I am in PowerShell. Now, I’ve already installed the PS2EXE module. So, what I want to do is just show you how PS2EXE works.
If I just type and press enter, you can see that right now I’ve got a couple of files in this folder. The main file that I want to show you is Calc.ps1. This is a calculator script that I created late last year.
The other file is Calc.ico. This is just a calculator icon that I downloaded from one of the many sites that offers free icons. I honestly can’t even remember which site I got this from.
We’ll come back to that file a little bit later.
For right now, what I want to do is convert Calc.ps1 into an executable file. So, the way that I do that is by typing . Then I type whatever I want to call the executable file. Because calc.exe is a Windows executable, I don’t want to reuse that. Instead, I’m just going to call this mycalc.exe.
ps2exe calc.ps1 mycalc.exe
I’ll press Enter, and just like that, the new executable file has been created.
I’ll go ahead and switch over to my Command Prompt window. I’ll and you can see the new file right here. If I run that file, you can see that it executes.
Incidentally, whenever you compile a PowerShell script into an executable file, you no longer have to worry about execution policies. Even if I were to set my execution policy to “restricted,” the calculator app would still run because now we’re running it as an executable rather than as a PowerShell script.
So, let me go ahead and close this out.
Simplifying PS2EXE With win-ps2exe
So, the big question I’m sure some of you are wondering right now is, “Is there any way to take advantage of all these parameters but simplify the syntax a bit?” Well, there actually is a shortcut that you can use. What you can do rather than dealing with all these parameters individually is type:
When you’re done, just click Compile, and the file that you’ve specified will be created.
So, that’s just a quick introduction to how you can compile a PowerShell script into an executable. I’m Brien Posey. Thanks for watching.
About the Author(s)
Brien Posey is a bestselling technology author, a speaker, and a 20X Microsoft MVP. In addition to his ongoing work in IT, Posey has spent the last several years training as a commercial astronaut candidate in preparation to fly on a mission to study polar mesospheric clouds from space.